title: Calling a PHP function from an HTML form in the same file
body: <p>I'm trying to execute a PHP function in the same page after the user enters a text and presses a submit button.</p>
  
  <p>The first I think of is using forms. When the user submits a form, a PHP function will be executed in the same page. The user will not be directed to another page. The processing will be done and displayed in the same page (without reloading).</p>
  
  <p>Here is what I reach to:</p>
  
  <p>In the <strong>test.php</strong> file:</p>
  
  <pre><code>&lt;form action="test.php" method="post"&gt;
      &lt;input type="text" name="user" placeholder="enter a text" /&gt;
      &lt;input type="submit" value="submit" onclick="test()" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The PHP code [ <strong><code>test()</code> function</strong> ] is <strong><em>in the same file</em></strong> also:</p>
  
  <pre><code>&lt;?php
      function test() {
          echo $_POST["user"]; // Just an example of processing
      }
  ?&gt;
  </code></pre>
  
  <p>However, I still getting a problem! Does anyone have an idea?</p>