我下面的代码检查是否有任何未输入的字段,然后检查验证问题是当没有错误时它仍然显示第一个 error_message .=
例如
$error_message .= "<div class=\"error-header\">Error: You did not submit the following required information.</div>";
$error_message .= "<ul id=\"errors\">"
// this part in the second else statement always shows how do i stop that;
完整代码在这里:
if((!$email_address)||(!$password)||(!$confirm_password)||(!$first_name)||(!$last_name)||(!$address)||(!$postal_code)||(!$region)||(!$country)) {
$error_message .= "<div class=\"error-header\">Error: You did not submit the following required information.</div>";
$error_message .= "<ul id=\"errors\">";
if(!$email_address) {
$error_message .= "<li>Please enter you're email address.</li>";
}
etc...
}else {
$error_message .= "<div class=\"error-header\">Error: The following information is invalid.</div>";
$error_message .= "<ul id=\"errors\">";
if($row_count > 0) {
$error_message .= "<li>The email address you provided is already in use, please use another email address.</li>";
}
if($confirm_password != $password) {
$error_message .= "<li>The passwords do not match.</li>";
}
if(!isset($_POST["interests"]) || count($_POST["interests"]) < 3) {
$error_message .= "<li>Please choose three departments that are of interest to you.</li>";
}else{
$interests = $_POST["interests"];
}
if(strtolower($captcha_code) == strtolower((string)$_SESSION["captcha"])) {
$error_message .= "<li>The code you entered is incorrect.</li>";
}
$error_message .= "</ul>";
}