我是新來的PHP,我不明白爲什麼這種形式在任何情況下提交... 所以我的問題是:表單提交,即使所有的字段都沒有填寫
怎麼辦我解決這個問題,所以表單只在用戶填寫所有字段時才提交。
if (!$_POST['username'] && !$_POST['password'] && !$_POST['repassword']
&& !$_POST['user_firstname'] && !$_POST['user_lastname']){
header('Location: register.php?msg=You did not complete all of the required fields');
}
我同時使用&&
和||
運營商,但是始終提交不管您填寫哪個領域出。
<form action="createuser.php" method="post" name="registration_form" id="registration_form">
<label>Email</label>
<input name="username" type="text" id="username" size="50" maxlength="50" /><br />
<label>First Name</label>
<input name="user_firstname" type="text" id="user_firstname" size="50" maxlength="50" /><br />
<label>Last Name</label>
<input name="user_lastname" type="text" id="user_lastname" size="50" maxlength="50" /><br />
<label>Password</label>
<input name="password" type="password" id="password" size="50" maxlength="100" /><br />
<label>Re-type Password</label>
<input name="repassword" type="password" id="repassword" size="50" maxlength="100" /><br />
<input type="submit" value="Register" name="submit" />
在此先感謝您的幫助,這似乎是一個很棒的社區!
無論發生什麼,表單都會提交。聽起來你需要添加驗證,請參閱:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ –
使用空($ _ POST ['some_value'])而不是!$ _ POST ['some_value']比檢查字段是否真的是空的 – kalpaitch