0

I'll try to explain this as best as possible.

I have a form that on submit actions on email.php:

<form data-toggle="validator" role="form" method="POST" action="email.php">
                        <div class="row">
                            <!-- Full Name -->
                            <div class="form-group col-lg-4">
                                <label for="inputName" class="control-label">Name</label>
                                <input type="text" class="form-control" name="inputName" id="inputName" required>
                            </div>
                            <!-- email -->
                            <div class="form-group col-lg-4">
                              <label for="inputEmail" class="control-label">Email</label>
                              <input type="email" class="form-control" name="inputEmail" id="inputEmail" data-error="Incorrect Email Format" required>

                            </div>
                            <!-- phone number -->
                            <div class="form-group col-lg-4">
                                <label for="inputTel" class="control-label">Phone Number</label>
                                <input type="text" pattern="(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}" name="inputTel" id="inputTel" data-minlength="10" maxlength="15" class="form-control" placeholder="123-456-7890" data-error="(123)-456-7890 | 1234567890 | 123-456-7890"> 

                            </div>
                            <!-- message -->
                            <div class="form-group col-lg-12">
                                <label for="content" class="control-label">Message</label>
                                <textarea name="content" id="content" class="form-control" rows="6" data-minlength="5" data-error="Message Must be longer"></textarea>

                            </div>
                            <!-- button -->
                            <div class="form-group col-lg-12">
                               <button type="submit" class="btn btn-default">Submit</button>
                            </div>
                        </div>
                    </form>

After the form is successfully processed in email.php, I want it to go back to the page the form is located on and show the "thank you" modal I created

currently I have in email.php (after validation):

     echo "<script>

     $(window).load(function(){
         $('#myModal').modal('show');
     });
     window.location.href="Websitename";
</script>";

This does not work. What happens is the page just gets redirected but does not display the modal.

Can anyone please provide me any assistance?

Steven Marrocco
  • 111
  • 1
  • 10
  • Why don't you show the modal with a button that will redirect to `Websitename` while clicked ? Or just set a timeout to run `window.location.href="Websitename"` – TTCC Jul 27 '16 at 01:51

1 Answers1

0

I think the problem is in

        window.location.href="Websitename";

When browser see this line , she will automatically locate the browser which means new request immediately made. Let me explain : Your form send request to email.php -----> sends response as a javascript --> javascript request to "website name". In order to correct this issue , you should put window.location.href inside timeout function and that timeout triggered after window.load . Please check :

    echo "<script>
          function deferredFunction(){
 window.location.href="Websitename";
    }
         $(window).load(function(){
             $('#myModal').modal('show');
             setTimeout(deferredFunction,5000);
         });   
    </script>";

Hope Helps!!

Osman Corluk
  • 325
  • 1
  • 3
  • 12
  • 35 seconds late :D – Ismail RBOUH Jul 27 '16 at 01:50
  • thank you! Unfortunately this did not solve me issue. I'm still hanging on the email.php thread with no redirect or modal being displayed. Does the email.php have to include any bootstrap links to work? – Steven Marrocco Jul 27 '16 at 02:50
  • check the comments on (http://stackoverflow.com/questions/4584373/difference-between-window-load-and-document-ready-functions) . please change $(window).load to $(document).ready – Osman Corluk Jul 27 '16 at 10:49
  • I have though changed it from a modal to just an alert and it works exactly how I intended. Does this information help? – Steven Marrocco Jul 27 '16 at 18:41
  • Can you please send email.php all content. May be #modal lives in form submissin – Osman Corluk Jul 27 '16 at 18:44
  • Please use debugging tools on your browser by pressing F12 in Firefox or Chrome and check and send me the console error information . – Osman Corluk Jul 28 '16 at 00:58