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/interest.fcgi

    r222 r238  
    1111use Email::Valid;
    1212
    13 use vars qw($dbname $dbhost $dbuser $dbpass);
    14 
    1513# Find our private perl libraries
    1614use FindBin;
    1715use lib "$FindBin::Bin/../perllib";
    1816use NPEMap;
    19 
    20 sub print_err;
    2117
    2218my $returnlink='<a href="/">Go back</a>';
     
    3430    # In case the database went away, make sure we have a connection
    3531    unless ($dbh = setup_dbh()) {
    36         print_err('Error setting up database connection', $returnlink);
     32        print_html_err('Error setting up database connection', $returnlink);
    3733        next REQUEST;
    3834    }
     
    4036    # Input validation
    4137    unless (defined $cgi->param('email')) {
    42         print_err ("Email address not supplied", $returnlink);
     38        print_html_err ("Email address not supplied", $returnlink);
    4339        next REQUEST;
    4440    }
    4541
    4642    unless(Email::Valid->address($cgi->param('email'))) {
    47         print_err ("Sorry, your email address doesn't seem to be valid", $returnlink);
     43        print_html_err ("Sorry, your email address doesn't seem to be valid", $returnlink);
    4844        next REQUEST;
    4945    }
    5046
    5147    unless (defined $cgi->param('scotland') or defined $cgi->param('northernireland')) {
    52         print_err ("Interest in neither Scotland nor Northern Ireland shown", $returnlink);
     48        print_html_err ("Interest in neither Scotland nor Northern Ireland shown", $returnlink);
    5349        next REQUEST;
    5450    }
     
    5753    my $sth = $dbh->prepare('SELECT email FROM interest WHERE email = ?');
    5854    unless ($sth->execute($cgi->param('email'))) {
    59         print_err('Database error', $returnlink);
     55        print_html_err('Database error', $returnlink);
    6056        next REQUEST;
    6157    }
    6258
    6359    if ($sth->rows) {
    64         print_err('We already have a record of your interest. Please email us if you wish to change or remove this.', $returnlink);
     60        print_html_err('We already have a record of your interest. Please email us if you wish to change or remove this.', $returnlink);
    6561        next REQUEST;
    6662    }
     
    8480        next REQUEST;
    8581    } else {
    86         print_err("Database error when adding your data :(", $returnlink);
     82        print_html_err("Database error when adding your data :(", $returnlink);
    8783        next REQUEST;
    8884    }
     
    9187# No more requests to serve, so tidy up
    9288$dbh->disconnect;
    93 
    94 # Helper routines
    95 sub print_err($$) {
    96     my $err = shift;
    97     my $returnlink = shift;
    98     print "Content-type: text/html\n\n";
    99     print "<html><head><title>Error submitting</title></head>\n";
    100     print "<body><p>The following error occurred whilst submitting data:\n";
    101     print CGI::escapeHTML($err);
    102     print "</p><p>$returnlink</p>\n";
    103     print "</body></html>\n";
    104 }
Note: See TracChangeset for help on using the changeset viewer.