php - Why 2 Clicks needed to submit form -
i submitting form via 2 submit buttons why needs 2 clicks submit form form looks below:
<form id="mychkform" method="post" class=""> <input type="email" class="form-control" id="email" name="email" placeholder="enter email" data-original-title="" title="" /> <input type="radio" name="cnt_as" checked="checked" value="cnt_as_guest"/> want continue guest<br/> <input type="radio" name="cnt_as" style="margin-top:10px" value="auth_fm_chk"/> have password <div class="input-group gst_chk"> <input type="submit" class="btn btn-red" id="cntgyes" value="continue guest"> </div> <div class="sggn_in" style="display:none"> <div class="input-group"> <span class="input-group-addon"><i class="fa fa-lock"></i></span> <input type="password" class="form-control" id="password" name="password" placeholder="password" data-original-title="" title="" /> </div><br/> <div class="input-group"> <input type="submit" class="btn btn-red" id="cntaurth" value="sign in"> <span id="loading" style="display:none"><img src="<?php echo $dir; ?>img/2.gif" /> please wait</span> </div> </div> </form>
my jquery looks below:
$(document).ready(function(){ $('input[type="radio"]').click(function(){ if($(this).attr("value")=="auth_fm_chk"){ $(".sggn_in").show(); $(".gst_chk").hide(); } if($(this).attr("value")=="cnt_as_guest"){ $(".sggn_in").hide(); $(".gst_chk").show(); } }); $("form#mychkform").submit(function(event) { event.preventdefault(); validate(); }); function validate(){ $('#cntgyes').click(function(){ function checkemail(){ var email = $("#email").val(); if((email.length < 6) || (email.indexof('@',0) < 1) || (email.lastindexof('@') != email.indexof('@',0)) || (email.lastindexof('@') > (email.length - 5)) || (email.lastindexof('.') > (email.length - 3)) || (email.lastindexof('.') < (email.length - 4)) || (email.indexof('..',0) > -1) || (email.indexof('@.',0) > -1) || (email.indexof('.@',0) > -1) || (email.indexof(',',0) > -1)){ $("#email").css("border-color","#f05f68"); return false; } else{ $("#email").css("border-color","#0c9"); return true; } } if(!checkemail()){ return false; } else{ var email = $("#email").val(); var datastring = 'email=' + email; $("#loading").show(); $.ajax({ url: "includes_fm/form_submi/checkou_guauth", type: "post", data: datastring, success: function (msg) { $("#loading").hide(); location.replace("checkout/guest_ckot?id_gst="+msg+"#pg2"); } }); } $('#cntaurth').click(function(){ function checkemail(){ var email = $("#email").val(); if((email.length < 6) || (email.indexof('@',0) < 1) || (email.lastindexof('@') != email.indexof('@',0)) || (email.lastindexof('@') > (email.length - 5)) || (email.lastindexof('.') > (email.length - 3)) || (email.lastindexof('.') < (email.length - 4)) || (email.indexof('..',0) > -1) || (email.indexof('@.',0) > -1) || (email.indexof('.@',0) > -1) || (email.indexof(',',0) > -1)){ $("#email").css("border-color","#f05f68"); return false; } else{ $("#email").css("border-color","#0c9"); return true; } } function checkpass(){ var password = $("#password").val(); if(password == 0){ $("#password").css("border-color","#f05f68"); return false; } else{ $("#password").css("border-color","#0c9"); return true; } } if(!checkemail() || !checkpass()) { return false; } else{ var email = $("#email").val();var password = $("#password").val(); var datastring = 'email=' + email + '&password=' + password ; $("#loading").show(); $.ajax({ url: "includes_fm/form_submi/login_submit", type: "post", data: datastring, success: function (msg) { if (msg == 1) { $("#loading").hide(); window.location.reload(); } else { $("#loading").hide(); $("#messagesuccerr").html("<span style=color:red; font-size:14px>oops!! wrong credentials!!</span>") .fadein().delay(4000).fadeout(); return false; } } }); } }); });
when click submit button of continue guest
have press button 2 times form validates field. why 2 clicks needed.
same happening on after validating email field. please assist.
your
validate
function has many errors (such unnecessary$('#cntaurth').click(function(){});
).span id="loading"
in incorrect place.div id="messagesuccerr"
missing.and other problems.
validate
function should like:
function validate() { if (!checkemail()) { return false; } var isuser = $(".sggn_in").is(':visible'); if (isuser) { if (!checkpassword()) { return false; } var url = "includes_fm/form_submi/login_submit"; var datastring = 'email=' + $("#email").val() + '&password=' + $("#password").val(); makerequest(url, datastring, successuserrequest); } else { var url = "includes_fm/form_submi/checkou_guauth"; var datastring = 'email=' + $("#email").val(); makerequest(url, datastring, successguestrequest); } }
Comments
Post a Comment