我有一個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)***或在哈希之前使用其他任何清理機制。這樣做*更改密碼並導致不必要的附加編碼。 –