title: PHP Login Form In Bootstrap 3 Modal
body: <p>I've started created a login form within a Bootstrap modal, I already have the code for the modal (simple bootstrap modal), and I have the PHP code to complete the login on a separate page (login.php), but I would like to have the login validate and return the errors inside the modal, possibly without refreshing the page. Here are examples: <a href="http://demo.flarum.org/#/" rel="nofollow">http://demo.flarum.org/#/</a> and <a href="https://phpacademy.org/" rel="nofollow">https://phpacademy.org/</a>, both have a login modal, and return errors as well as displaying a loading icon. </p>
  
  <p>Here is my modal code with the form:</p>
  
  <pre><code>&lt;div class="modal fade" id="modalSignin" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt;
  
    &lt;div class="modal-dialog modal-signin"&gt;
  
      &lt;div class="modal-content"&gt;
  
        &lt;div class="modal-header"&gt;
          &lt;h3 class="modal-title text-center"&gt;Sign In&lt;/h3&gt;
        &lt;/div&gt;
  
        &lt;div class="modal-body"&gt;
          &lt;form method="POST" class="form-signin"&gt;
              &lt;div class="form-group"&gt;
                  &lt;input type="text" class="form-control" name="username" placeholder="Username" autocomplete="off" autofocus="on"&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;input type="password" class="form-control" name="password" placeholder="Password"&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;button type="submit" class="btn btn-primary btn-block" name="submit"&gt;Sign In&lt;/button&gt;
              &lt;/div&gt;
          &lt;/form&gt;
        &lt;/div&gt;
  
        &lt;div class="modal-footer"&gt;
          &lt;p class="text-center text-muted"&gt;Don't have an account yet? &lt;a href="#"&gt;Sign Up&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
  
      &lt;/div&gt;
  
    &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>And here is the simple php code in login.php, (I know this code can be improved, but just as an example) that I would like to somehow attach to the modal.</p>
  
  <pre><code> if (!empty($_POST)) {
  
      $username = $_POST['username'];
      $password = $_POST['password'];
  
      if (empty($username) &amp;&amp; empty($password)) {
          $errors[] = 'Please enter a username and password!';
      }
  
      else if (empty($username)) {
          $errors[] = 'Please enter a username!';
      }
  
      else if (empty($password)) {
          $errors[] = 'Please enter a password!';
      }
  
      else {
  
          $login = login($username, $password);
  
          if (!$login) {
              $errors[] = 'Couldn\'t sign you in with those details!';
              echo outputErrors($errors);
          } else {
              $_SESSION['user'] = $login;
              redirect('index.php');
          }
  
      }
  
  }
  </code></pre>
  
  <p>I might be doing a lot wrong, but if someone could point me in the right direction or show me some example code that would be great.</p>
  
  <p>Thanks in advance! :)</p>