1

Gosh, that title was a bit of a mouthful.

Basically my question is quite hard to explain due to my bare knowledge of PHP but I have a contact form that once the submit button has been pressed, processes through an engine, then redirects to a confirmation page if all has worked out.

This confirmation page is a html document that is literally a h1 tag with some text, what I would like to do is have a confirmation show up on the original page with the contact form on it as a javascript notification (a NotifyJS type one)

My file structure: contact form: contact.html > contactengine.php (if no errors) > contactthanks.php

Here is the code

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

Here is the plugin I want to use for the error https://notifyjs.com/

This is my confirmation notification, that I want the contactthanks.php message to show up on (on the original page)

$.notify("Email sent succesfully");

Thanks in advance, been trying heaps of different things but I'm just getting nowhere, can't find any answers that make sense to me also.

  • Possible duplicate of [How do I redirect to another page in jQuery?](http://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-page-in-jquery) –  Jan 01 '17 at 10:53

1 Answers1

0

The flow does not seem clear.

You want a notification on the form page but you wouldn't see it because you are forwarded to either "thankyou" or "error".

I don't know exactly what you want but perhaps you want to fire the form through AJAX (which would execute it in the background and you stay on the form page) and then show the result (error or thankyou) in a notification.

Simon Kraus
  • 736
  • 4
  • 14
  • You should dive in Ajax. This would be what you want. You send the contact form contact via an Ajax call (use jQuery.ajax) to the contactengine.php which should just return the content of contactthanks or error. Then you set up a success function in the ajax call which does the notiification with the returned content. In this case you never leave your contact.html and everything should be fine. – Simon Kraus Mar 14 '16 at 09:29