title: Reload Bootstrap Modal on PHP variable not valid
body: <p>Having some problems with the error handling of a bootstrap modal. In the modal I have two inputs (both are required). I want to be able to display a simple "required" message if the form is submitted without one of the fields populated. </p>
  
  <p>I tried doing this with PHP and it works in a page by itself, but when I put it in a modal the modal closes on submit and then if you re-open the modal you see the error messages. I really want the modal to stay open or re-open if the input fields are not valid when the user submits. </p>
  
  <p>Any help would be appreciated! Thanks!</p>
  
  <p>HTML (Start of the modal):</p>
  
  <pre><code>&lt;div class="modal fade" id="createModal" tabindex="-1" role="dialog" aria-labelledby="createModal" aria-hidden="true"&gt;
      &lt;div class="modal-dialog"&gt;
         &lt;div class="modal-content"&gt;
             &lt;div class="modal-header"&gt;
                 &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
                 &lt;h4 class="modal-title" id="myModalLabel"&gt;Add a vCenter&lt;/h4&gt;
             &lt;/div&gt;
             &lt;div class="modal-body"&gt;
  </code></pre>
  
  <p>PHP (To graph the input and report any errors):</p>
  
  <pre><code> if ( !empty($_POST)) {
      // keep track validation errors
      $vcenternameError = null;
      $vcenterownerError = null;
  
      // keep track post values
      $vcentername = $_POST['vcentername'];
      $vcenterowner = $_POST['vcenterowner'];
  
      // validate input
      $valid = true;
      if (empty($vcentername)) {
          $vcenternameError = 'Please enter vCenter Name';
          $valid = false;
      }
  
      if (empty($vcenterowner)) {
          $vcenterownerError = 'Please select vCenter Owner';
          $valid = false;
      }
  
      // insert data
      if ($valid) {
  
          $sql = "INSERT INTO ";
                      $stmt = sqlsrv_query( $conn, $sql );
                      if( $stmt === false) {
                          die( print_r( sqlsrv_errors(), true) );
                      }
          header("Location: index.php");
      }
  }
  ?&gt;
  </code></pre>
  
  <p>HTML (the rest of the modal):</p>
  
  <pre><code>&lt;div class="panel-body"&gt;
      &lt;form class="form-horizontal" action="index.php" method="post"&gt;
          &lt;div class="&lt;?php echo !empty($vcenternameError)?'error':'';?&gt; form-group"&gt;
              &lt;div class="alert alert-warning"&gt;
                  Please input the FQDN of the vCenter and select an owner.
              &lt;/div&gt;
              &lt;label class="control-label"&gt;vCenter Name&lt;/label&gt;
              &lt;div class="controls"&gt;
              &lt;input name="vcentername" type="text" placeholder="vCenter Name" value="&lt;?php echo !empty($vcentername)?$vcentername:'';?&gt;" class="form-control"&gt;
                   &lt;?php if (!empty($vcenternameError)): ?&gt;
                      &lt;div class="alert alert-warning alert-dismissable"&gt;
                   &lt;?php echo $vcenternameError;?&gt;
                          &lt;/div&gt;
                          &lt;?php endif; ?&gt;
                      &lt;/div&gt;
                    &lt;/div&gt;
                  &lt;div class="&lt;?php echo !empty($vcenterownerError)?'error':'';?&gt; form-group"&gt;
                      &lt;label class="control-label"&gt;vCenter Owner&lt;/label&gt;
                      &lt;div class="controls"&gt;
  
                      &lt;div class="btn-group" data-toggle="button" role="group" aria-label="..."&gt;
                        &lt;label class="btn btn-default"&gt;
                          &lt;input type="radio" name="vcenterowner" value="Team1"&gt; Team1
                        &lt;/label&gt;
                        &lt;label class="btn btn-default"&gt;
                          &lt;input type="radio" name="vcenterowner" value="Team2"&gt; Team2
                        &lt;/label&gt;
                        &lt;label class="btn btn-default"&gt;
                          &lt;input type="radio" name="vcenterowner" value="Team3"&gt; Team3
                        &lt;/label&gt;
                      &lt;/div&gt;
                          &lt;?php if (!empty($vcenterownerError)): ?&gt;       
                              &lt;div class="alert alert-warning alert-dismissable"&gt;
                                  &lt;?php echo $vcenterownerError;?&gt;
                             &lt;/div&gt;
                          &lt;?php endif; ?&gt;
                      &lt;/div&gt;
                    &lt;/div&gt;
                   &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="modal-footer"&gt;
                         &lt;div class="form-actions"&gt;
  
                        &lt;button type="submit" class="btn btn-success"&gt;Add&lt;/button&gt;
                        &lt;a class="btn btn-default" href="index.php"&gt;Back&lt;/a&gt;
                      &lt;/div&gt;
                         &lt;/form&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  </code></pre>