我在注册页面
中使用JavaScript函数来检查注册页面中的所有字段是否已填写。
我正在使用表单
<form name="regform" onsubmit="return validateFormOnSubmit(this)" method="post" >
coding here......
</form>
onsubmit 我调用我的 javascript 函数 validateFormOnSubmit(this)
如上所示。
现在,如果所有字段均已收集,则意味着所有字段均已正确填写
现在我想将我的此页面发布到其他页面,例如 index.php
如何可能。
我的java脚本警报就像这样
function validateFormOnSubmit(theForm) {
var reason = "";
reason += validatereferrer(theForm.referrer);
reason += validateEmail(theForm.email);
reason += validatePassword(theForm.pw1, theForm.pw2);
reason += validatebuisinessname(theForm.buisinessname);
if (reason != "") {
alert("Please fix the following error(s) and resubmit:\n\n" + reason);
return false;
}
alert("All fields are filled correctly");
return false;
}
最佳答案
将表单上的操作
设置为您要转发到的页面。还要确保如果验证失败,validateFormOnSubmit()
返回 false
,从而中止 POST
请求。如果验证成功,它还应该返回 true
。
例如:
<form action="/index.php"
name="regform"
onsubmit="return validateFormOnSubmit(this)"
method="post">
coding here......
</form>
关于php - 字段验证后调用php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6844281/