title: How to redirect and inform the user if his or her password is incorrect?
body: <p>Assuming I have a block of code like this on a login page:</p>
  
  <pre><code>&lt;form action="login_action.php" method="post"&gt;
      &lt;div id="account"&gt;
          &lt;div class="form-label"&gt;Username:&lt;/div&gt;
          &lt;div class="form-input"&gt;&lt;input name="username" type="text" /&gt;&lt;/div&gt;
          &lt;div class="form-label"&gt;Password:&lt;/div&gt;
          &lt;div class="form-input"&gt;&lt;input name="password" type="password" /&gt;&lt;/div&gt;
          &lt;div class="form-submit"&gt;&lt;input type="submit" value="Submit" /&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The login_action file queries the database with the given credentials and if they are correct performs <code>$_SESSION['username'] = $username;</code></p>
  
  <p>This works fine. However, if the user provides incorrect credentials, ideally the page would not redirect and instead it would display an error message on the page on the line before username. This is the part I am confused on how to tackle.</p>
  
  <p>Would I instead have to capture the submit button press with JQuery and post the user credentials to the php file with AJAX? This would then get rid of the form on the login page. I suppose then I could return a string specifying whether or not the credentials were valid and if not, it would append a message to the account div that the credentials were incorrect.</p>
  
  <p>Would that be the standard approach to this sort of problem? Since recently discovering AJAX I am using it for almost everything and I'm not sure if in this case it is the ideal solution. Overriding the submit button's default behavior and removing the form seems kinda hacky to me but I'm not sure. Is this how SO would solve this?</p>