php - Ajax inside submitHandler form submit not working -
i working on registration user,
i validate fields jquery validation plugins.
in 'submithandler' called ajax , if response ok form submited ....but form not submited.but got alert of "ok".
here code,
jquery(document).ready(function(){ // setup form validation on #register-form element jquery("#reg_form").validate({ // specify validation rules errorelement: "span", rules: { fname: { required: true, maxlength: 12, minlength: 4, remote: {url: "<?php echo get_template_directory_uri() ?>/ajax-checkusername.php", type : "post"} }, lname: "required", phone: {required:true,number: true}, address: "required", email: { email: true, required: true, remote: {url: "<?php echo get_template_directory_uri() ?>/ajax-checkemail.php", type : "post"} }, password: "required", cpassword: { required: true, equalto: "#password" }, profile_picture: { accept: "image/*" } }, // specify validation error messages messages: { fname: { email: "this field required.", minlength: "please enter atleast 4 characters", maxlength: "too characters", remote: "username in use!", }, lname: "this field required.", phone: { required: "this field required", number: "please enter number" }, address: "this field required.", email: { required: "please enter email!", email: "this not valid email!", remote: "email in use!", }, password: "this field required.", cpassword :{ required:"this field required.", equalto:"password not matched." }, profile_picture: { accept:"please insert image" } }, submithandler: function(form) { var frm = $(form);alert(frm); if (jquery("#g-recaptcha-response").val()) { jquery.ajax({ type: 'post', url: "<?php echo get_template_directory_uri(); ?>/ajax_verify_captcha.php", // file we're making request datatype: 'html', async: true, data: { captcharesponse: jquery("#g-recaptcha-response").val() }, success: function (data) { alert(data); //jquery('#reg_form').get(0).submit(); if(data=="ok"){ frm.submit(); } //alert("everything looks ok"); // jquery('#reg_form')[0].submit(); }, error: function (xmlhttprequest, textstatus, errorthrown) { alert("you're bot"); alert(xmlhttprequest); return false; } }); } else { alert("please fill captcha!"); return false; } } }); });
first thing check value within if statement. use (data) see if defined @ or .length
see if set anything.
console.log(data=="ok"); if(data.length){ frm.submit(); }
you should return boolean or number , use parseint() ensure compare 2 variables of same data type.
Comments
Post a Comment