我有一个html表单,我希望在POST之前在PHP中运行Javascript中的验证。然而,尽管我已经为每个输入标签分配了名称并在form标签中指定了一个action属性,但直到PHP部分的链接似乎仍无法正常工作。无法通过JavaScript提交表单到php
这里是表单的HTML代码:
<form id="signupform" action="signupform.php" method="post">
<input type="text" name="Email" placeholder="Email Address" class="signupinput" id="email" />
<br />
<input type="password" name="Password" placeholder="Password" class="signupinput" id="passwordone" />
<br />
<input type="password" placeholder="Repeat Password" class="signupinput" id="passwordtwo" />
<br />
<input type="button" value="Sign Up" class="signupinput" onClick="verifypass()" id="submit" />
</form>
按钮调用我用发送到PHP之前验证我的表单值的JavaScript函数:
function verifypass() {
var form = document.getElementById("signupform");
var email = document.getElementById("email").value;
var password1 = document.getElementById("passwordone").value;
var password2 = document.getElementById("passwordtwo").value;
var emailcode = /^(([^<>()\[\]\\.,;:\[email protected]"]+(\.[^<>()\[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (emailcode.test(email)) {
if (password1.length > 6) {
if (password1 == password2) {
form.submit(); //this statement does not execute
} else {
$("#passwordone").notify("Passwords do not match!", {
position: "right"
})
}
} else {
$("#passwordone").notify("Password is too short!", {
position: "right"
})
}
} else {
$("#email").notify("The email address you have entered is invalid.", {
position: "right"
})
}
}
你的控制台在form.submit()上说什么? – Akintunde007
允许用户使用他们所需的[密码/短语](https://xkcd.com/936/)。 [不限制密码。](http://jayblanchard.net/security_fail_passwords.html) –
**请勿存储纯文本密码!**请使用PHP的[内置函数](http:// jayblanchard。 net/proper_password_hashing_with_PHP.html)来处理密码安全性。如果您使用的是小于5的PHP版本。5你可以使用'password_hash()'[兼容包](https://github.com/ircmaxell/password_compat)。确保你*** [不要越狱密码](http://stackoverflow.com/q/36628418/1011527)***或在哈希之前使用其他任何清理机制。这样做*更改密码并导致不必要的附加编码。 –