title: Call a PHP function after onClick HTML event
body: <p><strong>Purpose:</strong> 
  Call a PHP function to read data from a file and rewrite it. I used PHP only for this purpose - FileIO - and I'm new to PHP.</p>
  
  <p><strong>Solution?</strong>
  I tried through many forums and knew that we cannot achieve it normal way: onClick event > call function. How can we do it, are there other ways, particularly in my case?
  My HTML code and PHP code is on the same page: Admin.php.
  This is HTML part:</p>
  
  <pre><code>&lt;form&gt;
      &lt;fieldset&gt;
          &lt;legend&gt;Add New Contact&lt;/legend&gt;
          &lt;input type="text" name="fullname" placeholder="First name and last name" required /&gt; &lt;br /&gt;
          &lt;input type="email" name="email" placeholder="etc@company.com" required /&gt; &lt;br /&gt;
          &lt;input type="text" name="phone" placeholder="Personal phone number: mobile, home phone etc." required /&gt; &lt;br /&gt;
          &lt;input type="submit" name="submit" class="button" value="Add Contact" onClick="" /&gt;
          &lt;input type="button" name="cancel" class="button" value="Reset" /&gt;
      &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This is PHP part:</p>
  
  <pre><code>function saveContact()
  {
      $datafile = fopen ("data/data.json", "a+");
      if(!$datafile){
          echo "&lt;script&gt;alert('Data not existed!')&lt;/script&gt;";
      } 
      else{
          ...
          $contact_list = $contact_list . addNewContact();
          ...
          file_put_contents("data/data.json", $contact_list);
      }
  
      fclose($datafile);
  }
  
  function addNewContact()
  {
     $new = '{';
     $new = $new . '"fullname":"' . $_GET['fullname'] . '",';
     $new = $new . '"email":"' . $_GET['email'] . '",';
     $new = $new . '"phone":"' . $_GET['phone'] . '",';
     $new = $new . '}';
     return $new;
  }
  </code></pre>
  
  <p>Have a look at these code, I want to call saveContact when people click on Add Contact button. We can reload page if need so. FYI, I use JQuery, HTML5 in page as well.
  Thanks,</p>