The Form Verification codes and Form Verification Codes
Verification code is a commonly used function for registration, login, and other forms. to prevent malicious forms from being entered and submitted continuously, this poses a security risk. Generally, the verification code image can be switched randomly. The form can be successfully submitted only after the verification is successful remotely. Implemented the simple verification code Function
<Form>
<Div class = "joinCon"> <div class = "row"> <div class = "label"> <em class = "musTip"> * </em> User Name: </div> <div class = "cell"> <input type = "text" data-checkurl = "/supajaxcheck/checkusername" name = "username" class = "inTxt"> </div> <div class = "row"> <div class = "label"> <em class = "musTip"> * </em> password: </div> <div class = "cell"> <input type = "password" name = "password" class = "inTxt"> </div> <div class = "row"> <div class = "label"> <em class = "musTip"> * </em> confirm the password: </div> <div class = "cell"> <input type = "password" name = "repassword" class = "inTxt"/> </div> <div class = "row verBox"> <div class = "label"> <em class = "musTip"> * </em> Verification Code: </div> <div class = "cell verCode"> <input type = "text" data-checkurl = "/joinin/checkcode" class = "inTxt w115 fl n-invalid" name = "key"> <div class = "checkCode"> <a href =" javascript: return false; "> change one </a> </div>
</Form>
Js code snippet:
var verCode = $('div.verCode','form'); verCode.each(function(){ var box = $(this), img = $('img.checkPic', box), src = img.attr('src'), chg = $('a', box), ipt = $('input.checkCode', box); chg.on('click', function(e) { e.preventDefault(); e.stopPropagation(); var _src = src+'&'+$.now(); img.attr('src', _src); }); img.on('click', function(e) { e.preventDefault(); e.stopPropagation(); var _src = src+'&'+$.now(); img.attr('src', _src); }); });
PHP form verification code
Your verification code is not added for verification. Please give it a try.
Add the JS verification code to the webpage form
<Script>
Function chk (){
....
}
</Script>
<Form action = "result. asp" method = "post" onSubmit = "return chk ()">
...
</Form>
The chk () function is a verification function. return true when the submission condition is met; return false when the submission condition is not met