html - Redirect user back to original site after successful contact form PHP and get successful message -
i want redirect user original site after successful contact form want show success message, because when contact form success blank page... thank in advance help..
this html form:
<form id="form" class="blocks" action="validateform.php" method="post" onkeyup="foo();" name="newform"> <p style="color: #ff0000;padding: 0 0 0 6.4%">required fields(*)</p> <p> <label>name *:</label> <input type="text" class="text" name="name" /> </p> <p> <label>e-mail *:</label> <input type="text" class="text" name="email" /> </p> <p> <label>subject :</label> <input type="text" class="text" name="phone" /> </p> <p class="area"> <label>message *:</label> <textarea class="textarea" name="message"></textarea> </p> <p> <label> </label> <input type="submit" class="btn" value="send" /> </p> </form>
and php:
<?php if(isset($_post['email'])) { $email_to = "mymail"; $email_subject = ""; function died($error) { // edw mpainei mhnuma p tha emfanisei se periptwsh error echo "we sorry, find error(s) in form<br/> <br/>"; echo $error."<br /><br />"; echo "please go , fix these errors.<br /><br />"; die(); } if(!isset($_post['name']) || !isset($_post['email']) || !isset($_post['message'])) { } $name = $_post['name']; $email_from = $_post['email']; $message = $_post['message']; $error_message = ""; $email_exp = '/^[a-za-z0-9._%-]+@[a-za-z0-9.-]+\.[a-za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= '<br>the email address entered not appear valid.<br />'; } $string_exp = "/^[a-za-z .'-]+$/"; if(!preg_match($string_exp,$name)) { $error_message .= '<br>the first name entered not appear valid.<br />'; } if(strlen($message) < 2) { $error_message .= '<br>the comments entered not appear valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "name: ".clean_string($name)."\n"; $email_message .= "email: ".clean_string($email_from)."\n"; $email_message .= "message: ".clean_string($message)."\n"; $headers = 'from: '.$email_from."\r\n". 'reply-to: '.$email_from."\r\n" . 'x-mailer: php/' . phpversion(); mail($email_to, $email_subject, $email_message, $headers); ?> <?php } die(); ?>
when finish php contact form mailing code, @ moment code says:
die();
change to:
die('<meta http-equiv="refresh" content="0; url=http://example.com?bob=youruncle" />');
of course, change bob=uncle key=value want - nonsense string, or contact=sent, or whatever.
then, @ top of index.php
file, add:
<?php if ( isset($_get['bob'] ){ $message = 'contact form sent!'; }else{ $message = ''; }
javascript/jquery page:
$(document).ready(function(){ var sendmsg = "<?php echo $message; ?>"; if (sendmsg.length){ alert(sendmsg); } }); //end document.ready
or, more fancy:
$(document).ready(function(){ var sendmsg = "<?php echo $message; ?>"; if (sendmsg.length){ settimeout(function(){ $('body').append('<div id="thx" style="display:none;position:absolute;top:20%;left:30%;font-size:5rem;background:wheat;z-index:2;">thanks contacting us!</div>'); $('#thx').fadein(700,function(){ settimeout(function(){ $('#thx').fadeout(700); },3000); }); },3000); } }); //end document.ready
Comments
Post a Comment