1

My objective is to call a "Thank you" modal message after successfully sending a quotation to an email, but I can't find the right code to do so. This is how the page works. I will fill up the form, then after I submit it, it will load the form.php, which has the code to send the email from the user to the assigned email which the message is supposed to be sent. After that, form.php will confirm if the email was successfully sent or not. My problem is, suppose that the message was sent, how will I redirect to the main index.html with the "Thank you" modal open?

Here's my index.html code.

<form class="login-form" method="post" action="php/form.php" name="quote-form" role="form">
  <fieldset>
    <div class="form-group">
      <input type="text" name="name" class="form-control" placeholder="Your Name" required data-error="Your Name is required.">
    </div>
    <div class="form-group">
      <input type="text" name="phone_number" class="form-control" placeholder="Phone Number " required data-error="Phone Number is required.">
    </div>

    <div class="form-group">
      <input type="email" name="email" class="form-control" placeholder="Email Address" required data-error="Valid email is required.">
    </div>

    <! --Adding Radio button For Call Back -->
    <div class="form-group">
      <label>Request Phone Call?: <br>
        <input type="radio" value ="Yes " required data-error="required." name="call">
        <em>Yes</em><br>
        <input type="radio" value ="No" required data-error="required." name="call">
        <em>No</em><br>
      </label>
    </div>

    <div class="form-group">
      <textarea id="textinput" class="form-control" name="message" required rows="1" placeholder="Please provide the ff: &#10; -Location &#10; -Dimension (Total Area less openings, All side running meters for endcap computation) &#10; -Color &#10; -Profile (Cladding or Decking) &#10; -If Pick up / Shipment / Delivery &#10; -If with installation" maxlength="500"></textarea>
      Remaining characters: <span id="count"></span>
    </div>
    <div class="form-group">
      <label>
        <input type="checkbox" required data-error="checkbox is required.">
        <em>I agree with the <a data-dismiss="modal" aria-label="Close" data-toggle="modal" data-target=".bs-example-modal-md-5">(privacy policy)</a></em></label>
    </div>
    <button class="tg-theme-btn tg-theme-btn-lg" type="submit">Submit</button>
  </fieldset>
</form>

Here's my full form.php code:

<?php

//Variable Declaraton

$name = $_POST['name'];
$email = $_POST['email'];
$to_email = "someone@example.com";
$subject = "New Quote";
$phoneNumber = $_POST['phone_number'];
$call = $_POST['call'];
$message = "From: $email\n" . "Client Sender: $name \n" . "Client Number: $phoneNumber\n" . "Call Back?: $call\n" . "\n\n" . "Message: \n\n" .  $_POST['message'];
$headers = 'WPC Cladding & Decking Website <no-reply@aggtrading.com>';


//EMAIL CONFIRMATION
// --- Subject of confirmation email. ---------

$conf_subject = 'Your recent enquiry';

// Who should the confirmation email be from?
$conf_sender = 'AGGTE WPC Cladding & Decking <no-reply@aggtecomposites.com>';
$msg = "Your email: $email\n" . "Your Number: $phoneNumber\n" . "\n" ."Hi" ." ". $_POST['name'] . ",\n\nThank you for your recent enquiry. A member of our team will respond to your message as soon as possible.";
mail( $_POST['email'], $conf_subject, $msg, 'From: ' . $conf_sender );

//----------Send to company email. ---------

/* $send = @mail($to_email,$subject,$message,$headers); */
if(@mail($to_email,$subject,$message,$headers)) {
    echo "<script> location.href='../index.html';
        </script>";
}
else{
    echo "<h1>Message not sent.</h1>";
}

?>

Here's the modal dialog that should open after redirecting from form.php after sending the email:

<!--my modal-->
<div id="myModal" class="modal fade bs-example-modal-md-2" tabindex="-1" role="dialog">
  <div class="modal-dialog modal-md-2" role="document">
    <div class="modal-content">
      <div class="top_links"><a href="#" data-dismiss="modal" aria-label="Close">Close (X)</a></div>
      <h2 class="modal-title">GET A FREE QUOTE</h2>
      <p>Thank you for sending us message! Feel free to explore more on our website!</p>
    </div>
  </div>
</div>
<!--my modal-->

Note: Here's the if/else that will redirect to index.html after confirming that the email was successfully sent:

if(@mail($to_email,$subject,$message,$headers)) {
    echo "<script> location.href='../index.html'; </script>";
}
else{
    echo "<h1>Message not sent.</h1>";
}

Thank you!

Chandan
  • 11,465
  • 1
  • 6
  • 25
Janzen Go
  • 11
  • 4

1 Answers1

-1

First set up a message variable instead of echo

Something like

$message = "IT WAS A SUCCESS";

Then initialize the Modal with the bootstrap jQuery initialization and place the Modal and the initialization itself ,under an if Statement.

if (isset($message)) {
    Modal and initialization here
}

Set the message before the JavaScript redirect.

Pbd
  • 1,219
  • 1
  • 15
  • 32
Browyn Louis
  • 218
  • 3
  • 14