jquery - execute php mail function through ajaxsubmit for contact form without redirecting to php file -



jquery - execute php mail function through ajaxsubmit for contact form without redirecting to php file -

class="snippet-code-js lang-js prettyprint-override">function contactform(){ function e(e){ var t=/^([a-za-z0-9_.+-])+\@(([a-za-z0-9-])+\.)+([a-za-z0-9]{2,4})+$/; return t.test(e) } $(".js-contact-form").submit(function(){ $(this).ajaxsubmit({ data:{ email:$(".js-contact-email").text().replace(/(\r\n|\n| \r)/gm,"").replace(/\s+/g," "), user_message:$(".js-mail-message").text().replace(/(\r\n| \n|\r)/gm,"").replace(/\s+/g," ") }, beforesubmit:function(t,n,r){ var i=$(".js-contact-email"),s=$(".js-contact-name"),o= $(".js-contact-subject"),u=$(".js-contact-brief"),a=1; i.removeclass("js-error");s.removeclass("js- error");o.removeclass("js-error");u.removeclass("js-error"); if(i.text()===i.data("placeholder")){i.addclass ("js-error");a=0}else if(!e(i.text())){i.addclass("js-error");a=0}if(s.text()===s.data ("placeholder")){s.addclass("js-error");a=0}if(o.text()===o.data("placeholder")) {o.addclass("js-error");a=0}if(u.text()===u.data("placeholder")){u.addclass("js- error");a=0}if(!a)return!1}, success:function(e){ $(".js-mail-message").addclass("js-hidden"); $(".js-contact-submit").addclass("js-hidden"); $(".js-mail-success").removeclass("js-hidden") } });return!1}) } class="snippet-code-html lang-html prettyprint-override"><form action="http://naiknikunj.me/theme/6/email.php" name="contactform" id="contactform" accept-charset="utf-8" class="contact-form js-contact-form" method="post"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <p class="mail-message js-mail-message">hi name <span class="contact_name js-contact-name" data-placeholder="your name goes here" contenteditable="true">your name goes here</span> , looking <span class="contact_subject js-contact- subject" data-placeholder="website existing business" contenteditable="true">website existing business</span>. can reach me on <span class="contact_email js-contact- email" data-placeholder="youremailid@domainname.com" contenteditable="true">youremailid@domainname.com</span>. here's quick outline of i'm after: <span class="contact_brief js-contact- brief" data-placeholder="project requirement goes here" contenteditable="true">project requirement goes here</span>. i forwards hearing you.</p> <p class="mail-message js-mail-success js-hidden">thank you. have received message , in touch shortly.</p> <button class="btn btn- default js-contact-submit">send mail service <i class="sendmsg fa fa-location-arrow"></i></button> </div> </div> </form> happening upon entering fields message (thank you. have received message , in touch shortly.

) gets displayed , when no fields entered text comes in reddish color. above things must work , along mail service should work. suppose have php mail service function code in phpurl.php file, how remain on contact form page , create mailing part happen without page beingness redirected phpurl.php.

why not utilize (assuming you've validated form)

$(".js-contact-form").submit(function(e) { e.preventdefault(); $.ajax({ type:'post', url: 'php/secure-email.php', data:$('#contactform').serialize(), success: function(response) { $(".js-mail-message").addclass("js-hidden"); $(".js-contact-submit").addclass("js-hidden"); $(".js-mail-success").removeclass("js-hidden"); }, complete:function() { $('#contactform').each(function() { this.reset(); }); } }); });

then in php file utilize $_post vars mail service , if mail service sent echo true

php jquery forms ajaxsubmit

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -