When the user registers, you need to enter some content, give each form a flag value
Detects the flag value of a form when it loses focus
At the end of the submission, these flag values are correct before they can be submitted
But here's the problem:
If the user's focus now in the Verification Code input box, the user entered the verification code after the click the Submit button registration, no problem
Because the user moved the mouse from the Verification Code input box to the Submit button, the Verification code verification work has been completed, its flag value is already true
However, if the user submits with the ENTER key, and the focus is still in the captcha input box, it needs to be manually focusout () under the code
$("input:focus").focusout();for(var i=0;i<$("input").length;i++){ if($("input").eq(i).attr('flag')==0){ return false; }}
Verification code in the session, this time to the background to detect the user's verification codes are correct, has not detected, the flag value of the form is still false, and then the following code is executed, to return false, resulting in the form cannot be submitted
I also wanted to give the for loop a delay so that when the user commits, those validations can be verified to complete
But in this case, the user does not enter anything, you can submit directly, the front desk verification is all voided
I do not know whether my description is clear enough, what has not been said to understand, can leave a message, thank you
Reply content:
When the user registers, you need to enter some content, give each form a flag value
Detects the flag value of a form when it loses focus
At the end of the submission, these flag values are correct before they can be submitted
But here's the problem:
If the user's focus now in the Verification Code input box, the user entered the verification code after the click the Submit button registration, no problem
Because the user moved the mouse from the Verification Code input box to the Submit button, the Verification code verification work has been completed, its flag value is already true
However, if the user submits with the ENTER key, and the focus is still in the captcha input box, it needs to be manually focusout () under the code
$("input:focus").focusout();for(var i=0;i<$("input").length;i++){ if($("input").eq(i).attr('flag')==0){ return false; }}
Verification code in the session, this time to the background to detect the user's verification codes are correct, has not detected, the flag value of the form is still false, and then the following code is executed, to return false, resulting in the form cannot be submitted
I also wanted to give the for loop a delay so that when the user commits, those validations can be verified to complete
But in this case, the user does not enter anything, you can submit directly, the front desk verification is all voided
I do not know whether my description is clear enough, what has not been said to understand, can leave a message, thank you
You can perform all the test conditions again when you are about to submit and check that all flags are true.
Can directly submit the verification code input value and background of the session to do, why to submit a front-end verification of the tag it? All submissions on the front end can be forged.
Before you submit an AJAX event, that is, to determine whether the verification code is correct, re-submit, incorrect popup window, do not submit.
Can prevent the above situation.
$("input[type=submit]").click(function(){ $("input:focus").focusout(); // 检测延时50s左右 setTimeout(function(){ var submitFlag=true; // 两个for循环可以抽出一个函数 for(var i=0;i<$("input").length-2;i++){ if($("input").eq(i).attr('flag')==0){ submitFlag=false; } } if(submitFlag){ $("form").submit(); } },100); for(var i=0;i<$("input").length-2;i++){ if($("input").eq(i).attr('flag')==0){ return false; } }});