我有一種形式。如果出現多個驗證錯誤,則必須顯示驗證錯誤,然後根據字段要求顯示所有錯誤或顯示。如何根據PHP中所需的字段顯示所有驗證錯誤?
例如,我有三個字段Name, Email
和Mobile
。如果所有信息都不正確,則逐個顯示所有驗證錯誤或任何一個字段不正確,然後顯示一個驗證錯誤。 我可以在jQuery驗證的幫助下顯示錯誤,我不想要。
/*alert notification for script*/
$(".notification_reminder").fadeIn()
.css({top:-100,position:'absolute'})
.animate({top:20}, 800, function() {
//callback
});
.form-section
\t \t {
padding: 30px;}
.form-section input
{
margin: 10px;
}
.notification_section
{
position: relative;
z-index: 8;
}
.notification_reminder
{
font-size:15px;
width:350px;
padding: 15px;
background-color:#1D9365;
margin: 0 auto;
}
.notification_reminder p
{
color:#FF0;
padding:3px;
box-sizing: border-box;
display: initial;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<?php if(!empty($_GET['chk_name'])):
\t echo"
\t \t <div class='notification_section'>
\t \t <div class='notification_reminder'>
\t \t <p> Name required Min 3 and Max 20</p>
\t \t </div>
\t \t </div>";
endif;?>
<?php if(!empty($_GET['chk_email'])):
echo"
\t \t <div class='notification_section'>
\t \t <div class='notification_reminder'>
\t \t <p> Enter valid Email address</p>
\t \t <div class='cross_sign'><i class='fa fa-times' aria-hidden='true'></i></div>
\t \t </div>
\t \t </div>";
endif;?>
<?php if(!empty($_GET['chk_mobile'])):
echo"
\t \t <div class='notification_section'>
\t \t <div class='notification_reminder'>
\t \t <p> 10 numbers only</p>
\t \t <div class='cross_sign'><i class='fa fa-times' aria-hidden='true'></i></div>
\t \t </div>
\t \t </div>";
endif;?>
<div class="form-section">
<form action="process.php" method="post">
\t <input type="text" name="name" placeholder="Name"><br />
\t <input type="email" name="email" placeholder="email"><br />
\t <input type="text" name="mobile" placeholder="mobile"><br />
\t <input type="submit" name="submit" >
</form>
</div>
Process.php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
if ($name <3 || $name >20) {
header('Location: test2.php?chk_name=1');
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header('Location: test2.php?chk_email=1');
}
if(strlen($mobile)!=10 || !is_numeric($mobile)) {
header('Location: test2.php?chk_mobile=1');
}
在process.php我用header
這是調用單驗證錯誤的原因。有沒有其他方法?你能幫我解決嗎?
什麼問題是什麼呢? –