Soldiers33 Posted May 10, 2009 Share Posted May 10, 2009 I have this code <?php $to = "admin@domain.co.uk"; $subject = "Submit Link"; $email = $_REQUEST['Title'] ; $message = $_REQUEST['URL'] ; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print " Message sent successfuly"; } else {print "We encountered an error sending your mail"; } ?> now when i submit the form the message sent successfuly would be put onto a new page, how can i make it so that it comes up as an alert box? Link to comment Share on other sites More sharing options...
0 C++ Posted May 10, 2009 Share Posted May 10, 2009 Assuming you want the alert of that same page you have now, just do this... <?php $to = "admin@domain.co.uk"; $subject = "Submit Link"; $email = $_REQUEST['Title']; $message = $_REQUEST['URL']; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers); if($sent) {print "<script>alert('Message sent successfully!');</script>"; } else {print "<script>alert('We encountered an error sending your mail');</script>"; } ?> Link to comment Share on other sites More sharing options...
0 Soldiers33 Posted May 10, 2009 Author Share Posted May 10, 2009 well the alert comes up now, but for some reason it still goes to a blank page. I need i to stay on the current page. Link to comment Share on other sites More sharing options...
0 C++ Posted May 10, 2009 Share Posted May 10, 2009 Well when you submit a form, you are redirecting the user to that script. There is no way around that. If that new script outputs nothing to the page then yes, the user will see a blank page. If you want them to never actually leave the form page and only see a Javascript alert when they submit your form, you have to use what is called an AJAX call instead of an actual form submission. This would mean Javascript reads your form fields, sends them to a different script in the background, and then outputs an alert to the page upon receiving a positive response from that other script. Have a look online at some AJAX tutorials online. You should be able to find some AJAX function pretty much ready-made. Link to comment Share on other sites More sharing options...
Question
Soldiers33
I have this code
now when i submit the form the message sent successfuly would be put onto a new page, how can i make it so that it comes up as an alert box?
Link to comment
Share on other sites
3 answers to this question
Recommended Posts