villa has asked for the wisdom of the Perl Monks concerning the following question:

Hello Perl Monks:)

I'm currently creating a CGI perl script which accepts entries from a HTML page.

Question:
How do I send a HTML error message to the user when he leaves any of the entry web-page fields blank?

Some of the variables I'm using which accept the entrys via the web-page are $candidate,$position & $education.

I believe I will probably need to use an IF else statement to make this work because if all entrys are inputted then at the end I will send a HTML confirmation message indicating that I have received your final entrys...

Best Rgds
Villa

Edit kudra, 2001-12-02 Changed title

  • Comment on How can I send an HTML error message to a user who leaves form fields blank?

Replies are listed 'Best First'.
(Ovid) Re: HELP! I need more perl wisdom...Thankyou:!
by Ovid (Cardinal) on Nov 30, 2001 at 02:04 UTC

    There are many ways to accomplish this. Here's one (untested):

    #!/usr/bin/perl -wT use strict; use CGI qw/:standard/; my %errors; my ( $candidate ) = ( param( 'candidate' ) =~ /^([\s\w]+)$/ ); # candidate must be defined and have at least one non-whitespace chara +cter if ( ! defined $candidate or $candidate !~ /\S/ ) { $errors{ candidate } = 'You must supply a value for candidate'; } # grab more params and untaint if ( %errors ) { display_page_with_errors( \%errors ); }

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      -T being one of the more important things you can learn doing web stuff.
Re: HELP! I need more perl wisdom...Thankyou:!
by Biker (Priest) on Nov 30, 2001 at 13:37 UTC

    It is helpful to the user if you send down JavaScript to the browser that will test this before sending the form up to the server.

    Important:
    Do not trust this as a final verification of the input. For anything that you think is important, you must do the final check on the server. Nevertheless, it is a good approach to let the user struggle with your form and get it pre-approved by your JavaScript before sending it through the 'net and bothering your server.

    Once you detect anything invalid at the server level (in your CGI script) you have no other tool than sending a full HTML page with your error messages down to the browser client.

    f--k the world!!!!
    /dev/world has reached maximal mount count, check forced.