0
我有一個表單,我希望在數據庫中添加值。它工作正常,爲驗證我已添加服務器端驗證,但錯誤,如果任何得到顯示窗體已提交後,我希望使用用戶端驗證的方式,如果用戶不輸入字段,不是輸入正確的格式或密碼不匹配時,錯誤應該同時顯示,即在點擊提交按鈕之前。誰能告訴它如何可以做到提交表單前顯示用戶結束錯誤
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (empty($_POST["email"]))
{
$emailErr = "Email is required";
}
else
{
$email =$_POST["email"];
}
if (empty($_POST["password"]))
{
$pswrdErr = "password is required";
}
else
{
$password = $_POST["password"];
}
if ($_POST["password"]!=$_POST["retype_password"])
{
$pswrdErr = "password does not match";
}
else
{
$password = $_POST["password"];
}
//insert query to add values in database
}
?>
<form name="form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" >
<input type="text" placeholder="Name" name="name"/>
<input type="email" placeholder="Email" name="email"/>
<input type="password" placeholder="Password" name="password"/>
<input type="password" placeholder="Retype Password" name="retype_password"/>
<button name ="submit" value = "submit" class="btn btn-greensea b-0 br-2 mr-5">Register</button>
</form>
可能的複製(http://stackoverflow.com/questions/16990378/javascript-form-validation-with-password-confirming) – Gavriel
重複的:http://stackoverflow.com/questions/15060292/a-simple-jquery-form-validation -script – Gavriel
你可以使用jquery驗證。 –