저는 등록 양식을 작성 중이며 사용자가 모든 필드를 채우지 않으면 오류를 표시하는 코드를 작성하려고합니다. 괜찮습니다.하지만 어떤 이유로 이메일을 입력 할 때만 작동합니다. 모든 입력란을 비워두고 등록을 클릭하면 오류가 발생하지 않고 모든 입력란이 비어있는 상태에서 등록란을 클릭하면 커서가 이메일 입력란으로 이동하여 활성화됩니다 (이 입력란). 이 이메일에 문제가 있어도 문제는 찾을 수 없으므로 잘못되었습니다.PHP가 필드가 비어 있는지 확인하십시오.
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>
이 질문의 상태가 무엇입니까? – chris85