Gossamer Forum
Home : General : Perl Programming :

need help handling errors

Quote Reply
need help handling errors
Hello everyone!

I'm writing a script that will take orders for a hosting company and i'm trying to figure out a better way to handle the errors that happen if the orderer doesn't fill in something or whatever. Here is what I have:

if ($FORM{'submit_order'}) {
if ($FORM{'package'} eq "select") { &error_order_form("<li>You need to select a Hosting Package</li>") }
if (!$FORM{'username'}) { &error_order_form("<li>You need to enter a Client's Area Username</li>") }
if (!$FORM{'password'}) { &error_order_form("<li>You need to enter a Client's Area Password</li>") }
if (!$FORM{'name'}) { &error_order_form("<li>You need to enter your Name</li>") }
if (!$FORM{'business_name'}) { &error_order_form("<li>You need to enter your Business / Organization Name</li>") }
if (!$FORM{'email'}) { &error_order_form("<li>You need to enter your E-mail Address</li>") }
if (!$FORM{'address'}) { &error_order_form("<li>You need to enter your Street Address</li>") }
if (!$FORM{'city'}) { &error_order_form("<li>You need to enter your City</li>") }
if (!$FORM{'state'}) { &error_order_form("<li>You need to enter your State</li>") }
if (!$FORM{'zipcode'}) { &error_order_form("<li>You need to enter your Zip Code</li>") }
if (!$FORM{'email'}) { &error_order_form("<li>You need to enter your E-mail Address</li>") }
else {

blah blah blah...

&order_has_been_taken;
}
}
else { &clean_order_form; }


as you can see, if an error happens, it prints the &error_order_form; subroutine with the whatever message but I quickly realized that the way i have it will print the subroutine for every error. I could just put elsif but it will only display one error message and then the next one after the orderer has fixed it and clicked submit. I want it to display all the error messages that occured in an unordered list, like I have it setup and like Links. So all i'm asking for is another way to handle these error that will display all the errors on the &error_order_form;. For general info, it is setup like Links: &clean_order_form; shows the order form; &error_order_form; display the form and whatever errors happened; and &order_has_been_taken; displays the done page.

Thanks a bunch and God bless!

<><------------><>
Daniel
http://www.christian-search.net
<><------------><>
Quote Reply
Re: need help handling errors In reply to
I provided codes for qango in the Links SQL Discussion Forum about three weeks ago and some other users in the Link 2.0 Customization Forum about two months ago.

Hint: Use a variable like $error rather than a subroutine call and then use a conditional statement using chomp to show cluster or individual errors.

Good luck!

Regards,

Eliot Lee
Quote Reply
Re: need help handling errors In reply to
To start with, instead of:
Code:
if (!$FORM{'username'}) { &error_order_form("<li>You need to enter a Client's Area Username</li>") }
You could do:
Code:
if (!$FORM{'username'}) { $error .= "<li>You need to enter a Client's Area Username</li>"; }
And then:
Code:
if ($error) { &error_order_form($error); }
You really ought to use regexp's for validation, too.

Happy Coding,

--Drew
http://www.FindingHim.com