我已經創建了一個在線表單,當用戶點擊提交時,我希望表單檢查錯誤(即缺少字段)。目前,我有表單逐個檢查字段,一旦遇到錯誤,它將退出而不檢查其餘字段。有什麼辦法可以將檢查錯誤的所有if語句合併爲一個。PHP表單 - 錯誤檢查
下面是代碼
//Code to check that the Student Name field is completed
if(empty($_POST['studentName']))
{
$studentNameError = "You did not enter the student name Wank";
//echo "<h3> $studentNameError </h3>";
exit();
}
//Code to check that the Tutor Name field is completed
if(empty($_POST['tutorName']))
{
echo "<h3>You did not select a tutor name. Please go back and select your name from the tutors list</h3>";
exit();
}
//Code to check that the Procedure field is completed
if(empty($_POST['procedure']))
{
echo "<h3>You did not select a procedure. Please go back and enter the name of the procedure which you undertook</h3>";
exit();
}
//Code to check that the Grade field is completed
if(empty($_POST['grade']))
{
echo "<h3>You did not select a grade. Please go back and select your grade from the drop down list</h3>";
exit();
}
//Code to check that the Student Reflection field is completed
if(empty($_POST['studentReflection']))
{
echo "<h3>The student did not enter any comments for this procedure. Student reflection is required for each procedure. Please go back and enter any comments</h3>";
exit();
}
//Code to check if the tick box is checked that the tutor comment is entered
if(!strlen($_POST['tutorComments']) && isset($_POST['alert']))
{
echo "<h3>You must enter a reason why you have clicked the alert box</h3>";
exit();
}
非常感謝,似乎太工作 – Mattrsa