javascript - php ajax one page contact form -
i working on 1 page ajax contactform . want send email php without leaving page , i'm lost. have no idea why not working
i'll show contact form. thank in advance. here form ..
html code
<article class="panel" style="background:url(img/cover/bg_panel_3.jpg); background-size:cover;" full-screen> <div style="padding-top:80px;"> <div class="row text-center centered"> <div id="contact-form"> <form id="contact-us" action="contact.php" method="post"> <ul> <li class="field" id="check-1"> <input class="input txt requiredfield wide alpha-only" name="contactname" id="contactname" value="<?php if(isset($_post['contactname'])) echo $_post['contactname'];?>" placeholder="name" onblur="check(this.value)" /> </li> <li class="field" id="check-2"> <input class="input wide mail-only txt requiredfield email" name="email" id="email" value="<?php if(isset($_post['email'])) echo $_post['email'];?>" placeholder="email" /> </li> <li class="field" id="check-3"> <input class="input wide hack-check sub-check requiredfield" name="subj" type="text" placeholder="subject" value="<?php if(isset($_post['subj'])) echo $_post['subj'];?>" /> </li> <li class="field" id="check-4"> <input class="input wide num-only requiredfield" name="num" type="text" placeholder="number" value="<?php if(isset($_post['num'])) echo $_post['num'];?>" /> </li> <li class="field" id="check-5"> <textarea class="input textarea wide hack-check msg-check txtarea requiredfield" name="comments" id="commentstext" class="txtarea requiredfield" placeholder="message:"> <?php if(isset($_post['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_post['comments']); } else { echo $_post['comments']; } } ?> </textarea> </li> </ul> <div class="medium primary btn pretty-btn"> <input name="submit" class="subbutton" type="submit" value="send" /> </div> <input type="hidden" name="submitted" id="submitted" value="true" /> </form> <?php } ?> <!-- end #contact --> </div> </div> </div> </article>
**js code **
$(document).ready(function() { $('form#contact-us').submit(function() { $('form#contact-us .error').remove(); var haserror = false; }); if(!haserror) { var forminput = $(this).serialize(); alert(forminput); $.post("contact-us.php",forminput, function(data){ $('form#contact-us').slideup("fast", function() { $(this).before('<p class="tick fg-white sans"><strong>thanks!</strong> email has been delivered. !</p>' ); }); }); } return false; }); });
php code
//if form submitted if(isset($_post['submitted'])) { $name = trim($_post['contactname']); $email = trim($_post['email']); $num = trim($_post['num']); $subject = trim($_post['subj']); $comments = trim($_post['comments']); $formcontent=" : $name \n email : $email \n subject : $subj \n phone number : $number \n \n message : $message"; $recipient = "example@mail.com"; $subject = "contact form query received"; $mailheader = "from: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("error encountered! please try again or write directly mentioned email address."); // set our boolean completion value true $emailsent = true; }
i suspect problem }); in code stopping $.post(...) call being called. quick lint of js shows up, careful reading.
var haserror = false; ======> }); <====== remove stuff. if(!haserror) {
Comments
Post a Comment