Ignore:
Timestamp:
Oct 29, 2006, 7:35:19 PM (15 years ago)
Author:
Dominic Hargreaves
Message:

Make CGIs use shared error functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/cgi/problem.fcgi

    r222 r238  
    1212use CGI::Fast qw/:standard -debug/;
    1313
    14 use vars qw($dbname $dbhost $dbuser $dbpass);
    15 
    1614# Find our private perl libraries
    1715use FindBin;
    1816use lib "$FindBin::Bin/../perllib";
    1917use NPEMap;
    20 
    21 sub print_err;
    2218
    2319# Set up database handler to try and make sure it's ready for the first
     
    3935    # In case the database went away, make sure we have a connection
    4036    unless ($dbh = setup_dbh()) {
    41         print_err('Error setting up database connection', $returnlink);
     37        print_html_err('Error setting up database connection', $returnlink);
    4238        next REQUEST;
    4339    }
     
    4541    # Input validation
    4642    unless (defined $cgi->param('comment')) {
    47         print_err ("Please supply a comment");
     43        print_html_err ("Please supply a comment", $returnlink);
    4844        next REQUEST;
    4945    }
    5046
    5147    if (defined $cgi->param('email') and ($cgi->param('email') ne '') and !(Email::Valid->address($cgi->param('email')))) {
    52         print_err ("Invalid email address supplied");
     48        print_html_err ("Invalid email address supplied", $returnlink);
    5349        next REQUEST;
    5450    }
     
    6662   
    6763    unless ($msg->send) {
    68         print_err ('Sorry, there was an error sending your message. Please email webmaster@npemap.org.uk instead.');
     64        print_html_err ('Sorry, there was an error sending your message. Please email webmaster@npemap.org.uk instead.', $returnlink);
    6965        next REQUEST;
    7066    }
     
    8076# No more requests to serve, so tidy up
    8177$dbh->disconnect;
    82 
    83 # Helper routines
    84 sub print_err($$) {
    85     my $err = shift;
    86     my $returnlink = shift;
    87     print "Content-type: text/html\n\n";
    88     print "<html><head><title>Error submitting</title></head>\n";
    89     print "<body><p>The following error occurred whilst submitting data:\n";
    90     print CGI::escapeHTML($err);
    91     print "</body></html>\n";
    92 }
Note: See TracChangeset for help on using the changeset viewer.