jquery - Refresh div on php form submit -
i have mail form, , want #emailform div refreshed confirmation on submit click. now, page reloads. not sure how set up.
here php:
<?php ini_set('display_errors',1); error_reporting(e_all); if(!isset($_post['submit'])) { //this page should not accessed directly. need submit form. echo "error; need submit form!"; } $name = $_post['name']; $email = $_post['email']; $purchasecode = $_post['purchasecode']; $vendor = $_post['vendor']; //validate first if(empty($_post['name']) || empty($_post['email']) || empty($_post['purchasecode']) || empty($_post['vendor'])) { echo "all fields required."; exit; } if(isinjected($email)) { echo "bad email value!"; exit; } $email_from = $email; $email_subject = "gdfy purchase confirmation"; $email_body = "new purchase confirmation $name.\n". "here details:\n\n name: $name \n\n email: $email \n\n purchase code: $purchasecode \n\n vendor: $vendor"; $to = "idc615@gmail.com";//<== update email address $headers = "from: $email_from \r\n"; $headers .= "reply-to: $email_from \r\n"; //send email! mail($to,$email_subject,$email_body,$headers); //done. redirect thank-you page. header('location: index.html'); // echo "success"; // function validate against email injection attempts function isinjected($str) { $injections = array('(\n+)', '(\r+)', '(\t+)', '(%0a+)', '(%0d+)', '(%08+)', '(%09+)' ); $inject = join('|', $injections); $inject = "/$inject/i"; if(preg_match($inject,$str)) { return true; } else { return false; } } ?>
my html:
<div id="emailform"> <h2>confirm purchase information</h2> <hr> <form method="post" name="contactform" action="mail_form.php"> <p> <label for='name'>your name:</label> <br> <input type="text" name="name"> </p> <p> <label for='email'>email address:</label> <br> <input type="text" name="email"> </p> <p> <label for='purchasecode'>purchase code:</label> <br> <input type="text" name="purchasecode"> </p> <p> <label for='vendor'>vendor name:</label> <br> <select name="vendor"> <option value="" selected="selected"></option> <option value="amazon" >amazon</option> <option value="barnes&noble" >barnes & noble</option> <option value="family christian" >family christian</option> <option value="christianbook" >christianbook.com</option> <option value="lifeway" >lifeway</option> <option value="bam" >books-a-million</option> <option value="mardel" >mardel</option> </select> </p> <button type="submit" id="submitbutton" name="submit" value="submit" class="mainbutton">submit</button><br> </form> <!-- code validating form visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml details --> <script type="text/javascript"> var frmvalidator = new validator("contactform"); frmvalidator.addvalidation("name","req","please provide name"); frmvalidator.addvalidation("email","email","please enter valid email address"); frmvalidator.addvalidation("vendor","dontselect=000"); frmvalidator.addvalidation("purchasecode","maxlen=50"); </script> </div>
my javascript:
$('#submit').submit(function() { // catch form's submit event $.ajax({ // create ajax call... data: $(this).serialize(), // form data type: $(this).attr('method'), // or post url: $(this).attr('action'), // file call success: function(response) { // on success.. $('#emailform').html("<h1>thank you!</h1>thank submitting form. contact soon!"); // update div } }); return false; // cancel original event prevent form submitting });
your form has no id
, least of 1 matching #submit
. handler isn't attaching anything.
<form method="post" name="contactform" action="mail_form.php" id="submit">
should fix that.
Comments
Post a Comment