Please help with PHP error message
Posted: Tue Feb 26, 2008 12:33 am
Hi,
Just wondering if I could please get some help to modify some PHP code. The code is used to validate a web form. If there is an error in how the form is completed, an error message is generated. My problem is, how the code stands currently, if there are multiple errors in the form i.e invaild phone number and invaild e-mail address, both error messages are displayed. I would like to modify the code to only show one error message. Then once that error is corrected, the other error notification can be displayed.
Here is the current code:
Thanks a lot for your help,
Jo
Just wondering if I could please get some help to modify some PHP code. The code is used to validate a web form. If there is an error in how the form is completed, an error message is generated. My problem is, how the code stands currently, if there are multiple errors in the form i.e invaild phone number and invaild e-mail address, both error messages are displayed. I would like to modify the code to only show one error message. Then once that error is corrected, the other error notification can be displayed.
Here is the current code:
Code: Select all
function build_message($request_input){if(!isset($message_output)){$message_output ="";
}
if(!is_array($request_input)){$message_output = $request_input;
}
else{foreach($request_input as $key => $value)
{
if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;
}
else{$message_output .= build_message($value).", ";
}}}}
return rtrim($message_output,", ");}
$message = build_message($_REQUEST);
$message = stripslashes($message);
$subject = "Online Form";
$headers = "From: " . $_REQUEST['email'];
mail($my_email,$subject,$message,$headers);
Thanks a lot for your help,
Jo