title: How to write success message of form in bootstrap modal?
body: <p><strong>SOLVED</strong></p>
  
  <p>Ok, I solved the problem with AJAX but I had to delete my WordPress because it didn't work with it so later I will upload back by individual directory. Luckily I don't need it for my index. The working code is by <a href="https://www.codexworld.com/bootstrap-modal-popup-form-submit-jquery-ajax-php/" rel="nofollow noreferrer">CodexWorld</a>. I hope I help someone who is helpless.</p>
  
  <hr>
  
  <p>I am searching for solution all day but I don't get relevant solution anywhere. Other similar questions here are old, maybe there are fresh solution.</p>
  
  <p>So I am using Bootstrap the first time (files are on the themes of Wordpress). I started to build a contact form in Modal and if I hit submit the window closes, I get the e-mail, but the success-message only shows if I reopen it. I tried every solution I found on internet.</p>
  
  <p>I am not familiar with javascript and jquery, I don't know how to use it.</p>
  
  <p>In the footer I implemented:</p>
  
  <pre><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>In index there is the form with Modal:</p>
  
  <pre><code> &lt;!-- Modal --&gt;
      &lt;div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"&gt;
        &lt;div class="modal-dialog" role="document"&gt;
          &lt;div class="modal-content"&gt;
      &lt;form class="form-horizontal clearfix" id="contact-form" name="contact" role="form" method="post" action="index.php"&gt;
            &lt;div class="modal-header"&gt;
              &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
              &lt;h4 class="modal-title" id="myModalLabel"&gt;Küldj egy üzenetet&lt;/h4&gt;
            &lt;/div&gt;
            &lt;div class="modal-body"&gt;
  
  &lt;/div&gt;
  
  
  &lt;div class="form-group"&gt;
      &lt;label class="col-sm-2 control-label"&gt;Itt landol&lt;/label&gt;
      &lt;div class="col-sm-10"&gt;
        &lt;input class="form-control" id="disabledInput" type="text" placeholder="hello@kanizsaipatricia.hu" disabled&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;label for="name" class="col-sm-2 control-label"&gt;Név&lt;/label&gt;
          &lt;div class="col-sm-10"&gt;
              &lt;input type="text" class="form-control" id="name" name="name" placeholder="Minta János" value="&lt;?php echo htmlspecialchars($_POST['name']); ?&gt;"&gt;
              &lt;?php echo "&lt;p class='text-danger'&gt;$errName&lt;/p&gt;";?&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="email" class="col-sm-2 control-label"&gt;Email&lt;/label&gt;
          &lt;div class="col-sm-10"&gt;
              &lt;input type="email" class="form-control" id="email" name="email" placeholder="valaki@email.hu" value="&lt;?php echo htmlspecialchars($_POST['email']); ?&gt;"&gt;
              &lt;?php echo "&lt;p class='text-danger'&gt;$errEmail&lt;/p&gt;";?&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="message" class="col-sm-2 control-label"&gt;Üzenet&lt;/label&gt;
          &lt;div class="col-sm-10"&gt;
              &lt;textarea class="form-control" placeholder="Ide írd az üzenetet" rows="4" name="message"&gt;&lt;?php echo htmlspecialchars($_POST['message']);?&gt;&lt;/textarea&gt;
              &lt;?php echo "&lt;p class='text-danger'&gt;$errMessage&lt;/p&gt;";?&gt;
          &lt;/div&gt;
      &lt;/div&gt;
          &lt;/div&gt;
  
                          &lt;?php echo $result; ?&gt;
  
        &lt;div class="modal-footer"&gt;
          &lt;button type="button" class="btn btn-cancel hvr-fade" data-dismiss="modal"&gt;Mégsem&lt;/button&gt;
          &lt;input type="submit" id="submit" name="submit" data-toggle="modal" data-target="#resultModal" value="Elküldöm" class="btn btn-info hvr-wobble-horizontal"&gt;
      &lt;/div&gt;  
  &lt;/pop:form&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>The php code behind the form:</p>
  
  <pre><code>if (isset($_POST["submit"])) {
      $name = $_POST['name'];
      $email = $_POST['email'];
      $message = $_POST['message'];
      $from = 'Üzenetküldő űrlap'; 
      $to = 'hello@kanizsaipatricia.hu'; 
      $subject = 'Új üzenet formon keresztül';
  
      $body = "Feladó: $name\n E-Mail: $email\n Üzenet:\n $message";
  
      // Check if name has been entered
      if (!$_POST['name']) {
          $errName = 'Kérlek, add meg a neved!';
      }
  
      // Check if email has been entered and is valid
      if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
          $errEmail = 'Nem érvényes e-mail cím!';
      }
  
      //Check if message has been entered
      if (!$_POST['message']) {
          $errMessage = 'Nem írtál üzenetet.';
      }
  
  
  // If there are no errors, send the email
  if (!$errName &amp;&amp; !$errEmail &amp;&amp; !$errMessage) {
      if (mail ($to, $subject, $body, $from)) {
          $result='&lt;div class="alert alert-success noshadow"&gt;Elküldve.&lt;/div&gt;';
      } else {
          $result='&lt;div class="alert alert-danger noshadow"&gt;Sajnálom, hiba lépett fel az üzenet küldése közben. Próbáld újra!&lt;/div&gt;';
      }
  }
  }
  </code></pre>
  
  <p>I'm open minded for any solution in any language! Please help!</p>