我试图使用PHP表单执行mysql查询.以下是表格
Untitled Document Sign Up Now!Sign up and tell us what you think of the site!
我在Javascript中有以下表单验证,
function CheckTerms(){ var letter = /^[a-zA-Z ]*$/; if(document.myForm.First_Name.value.match(letter) && document.myForm.First_Name.value =="") { document.getElementById("error").innerHTML = "* Please Provide First Name"; document.myForm.First_Name.focus(); return false; } if(document.myForm.Last_Name.value.match(letter) && document.myForm.Last_Name.value =="" ) { document.getElementById("error_l").innerHTML = "* Please provide your Last name!"; document.myForm.Last_Name.focus() ; return false; } var email =/^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/; if(document.myForm.Email_i.value.match(email) && document.myForm.Email_i.value=="") { document.getElementById("error_e").innerHTML = "* Please provide your EMAIL!"; document.myForm.Email_i.focus() ; return false; } var min = 6; var max = 15; if(document.myForm.pass.value.length < min || document.myForm.pass.value.length > max) { document.getElementById("error_p").innerHTML = "Password Should be betweeen 6 to 15 characters"; document.myForm.pass.focus() ; return false; } var pass = document.getElementById("Pass").value; var re = document.getElementById("RePass").value; if(pass != re) { document.getElementById("error_rp").innerHTML = "Password do not match"; return false; } if(document.getElementById("check_box").checked == false) { document.getElementById("error_lable").innerHTML = "Please Check"; return false; }}
但问题是,即使javascript返回错误,单击提交按钮,执行PHP脚本导致数据进入数据库.如果存在任何javascript错误,我想停止表单提交.
即使您在函数中执行它,也不会在事件中返回布尔值.默认onSubmit
接收true
并提交.
更改
onsubmit="CheckTerms()"
至
onsubmit="return CheckTerms()"