【发布时间】:2017-11-11 16:39:37
【问题描述】:
我正在做一个注册表单,我正在尝试编写一个代码,如果用户没有填写所有字段,它将显示错误。它工作正常,但由于某种原因,它只有在我输入电子邮件时才有效。如果我将所有字段留空并单击注册,我不会收到任何错误,并且在所有字段为空的情况下,当我单击注册按钮时,我的光标会转到电子邮件字段并被激活(此字段)。 这封电子邮件有问题,但我找不到任何问题,所以有什么问题?
PHP源码:
if(empty($_POST['fname']) || empty($_POST['lname']) || empty($_POST['email']) || empty($_POST['password']))
{
$error="Fill all fields!";
}
HTML:
<form action="register.php" method="POST">
<input style="margin-top:10px" type="text" value="First Name" name="fname" onblur="if (this.value == '') {this.value = 'First Name';}" onfocus="if (this.value == 'First Name') {this.value = '';}" />
<input type="text" value="Last Name" name="lname" onblur="if (this.value == '') {this.value = 'Last Name';}" onfocus="if (this.value == 'Last Name') {this.value = '';}" />
<input type="email" value="Adres e-mail" name="email" onblur="if (this.value == '') {this.value = 'Adres e-mail';}" onfocus="if (this.value == 'Adres e-mail') {this.value = '';}" />
<p><input type="password" value="Password" name="password" onblur="if (this.value == '') {this.value = 'Password';}" onfocus="if (this.value == 'Password') {this.value = '';}" /></p>
<button type="submit" name="submit"> Register</button> </br>
</br>
</form>
【问题讨论】:
-
这个问题的状态是什么?