html - PHP cancel redirection after script execution -


i have simple post script php sends email, when click submit button executes , goes script directory (ex: localhost/sendmail/test.php). possible post alert box, , stay on page instead of going script , redirecting onto submit page?

this script.

<?php $subject = 'your website: contact'; // subject of email $to = 'myemail';  // enter recipient's e-mail address $emailto = $_request['email'];  $headers = "mime-version: 1.1"; $headers .= "content-type: text/html; charset=iso-8859-1"; $headers .= "from: " . $emailto . "\r\n"; // sender's e-mail $headers .= "return-path:". $emailto;  $body = 'you have received new inquiry!' . "\n\n"; $body .= 'name: ' . $_request['name'] . "\n"; $body .= 'email: ' . $_request['email'] . "\n"; $body .= 'phone: ' . $_request['phone'] . "\n\n"; $body .= 'message: ' . $_request['message'];  if($_request['name'] != "" && $_request['email'] != "" && $_request['phone'] != "" && $_request['message'] != "") {     if (@mail($to, $subject, $body, $headers))     {         // transfer value 'sent' ajax function showing success message.         echo 'sents';     }     else     {         // transfer value 'failed' ajax function showing error message.         echo 'failed';     } } else {     $message = "invalid fields!";     echo "<script type='text/javascript'>alert('$message');</script>";     //header("location: http://localhost/abtek/contact.html");     exit; } ?> 

so when alert executed, possible stop going script, , instead staying on page until fields valid submit? when submitted display alert again , stay on page instead of doing bunch of redirects.

any appreciated.

you can submit form ajax/jquery , stop redirect. see here: stackoverflow


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

c# - Json.Net Serialize String from URI -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -