Please help with PHP error message

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jovankau
Forum Newbie
Posts: 10
Joined: Tue Feb 26, 2008 12:25 am

Please help with PHP error message

Post by jovankau »

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:

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
easyredboy
Forum Newbie
Posts: 9
Joined: Tue Feb 26, 2008 12:18 am

Re: Please help with PHP error message

Post by easyredboy »

Hey,
The most imp thing is did the mail go
if the mail went then we can hide the error message
jovankau
Forum Newbie
Posts: 10
Joined: Tue Feb 26, 2008 12:25 am

Re: Please help with PHP error message

Post by jovankau »

Yes, details are sent in an email.

From you reply, I think I have been focusing on the wrong part of the code. I'm looking to edit the error message sent to user when user incorrectly completes the web form to only show the user 1 error message at a time, rather than all errors.

Think this is the correct part of the code that needs editing:

Code: Select all

 
 
if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}
 
if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}
 
 
P.S Sorry I am very new to PHP

Jo
Post Reply