Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Displaying an Error

by Anonymous Monk
on Jul 11, 2000 at 06:19 UTC ( #21902=perlquestion: print w/replies, xml ) Need Help??

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

Lets say i have a registration form html that a user fills up and hits the submit button leaving some fields empty. Now my perl scripts checks it and found an empty fied. Problem is how do i display the error message saying u left this field blank back to the registration form html? I know that i would use the redirect option but how do i display the error? Syntax i use for redirecting to another page is :
"<META http-equiv='REFRESH' content='1;URL= +thing/registered.htm'>"
Hope u could help me on this one...

Replies are listed 'Best First'.
Re: Displaying an Error
by httptech (Chaplain) on Jul 11, 2000 at 06:57 UTC
    I agree with Russ, don't use a redirect. It is confusing to users, because they won't know what they did wrong.

    I usually just take an array of "required" field names and loop through it and any that are blank get added to a scalar that contains an HTML list, like so:

    use CGI; my $q = new CGI; my $missed; my @required = qw(name address phone email); for (@required) { $missed .= "<li>$_</li>\n" if $q->param($_) eq ""; } do { print "Content-type: text/html\n\n"; print qq~ You forgot to fill in the following required fields: <ul>$missed</ul> ~; } if $missed;
Re: Displaying an Error
by Russ (Deacon) on Jul 11, 2000 at 06:27 UTC
    See a similar Categorized Q&A question at How do I detect and handle empty form fields?

    (Use this link until vroom finishes fixing the other link syntax)

    Now, I think you probably do not want to use a redirect. Send the form back, with the fields populated with what the user did enter. A co-worker of mine likes to put some kind of arrow graphic next to each field requiring the user's attention. You could also give empty fields a boldface label or use some other device to draw attention to the empty fields. If you don't detest javascript, you could even pop up a dialog telling the user what just happened, with instructions on how to fix it.

    Good luck...

    Brainbench 'Most Valuable Professional' for Perl

RE: Displaying an Error
by BigJoe (Curate) on Jul 11, 2000 at 06:43 UTC
    Please-Please Use the code tags to enter in the metarefresh. My suggestion is don't use a meta-refresh. Use something like this
    use CGI; $q = new CGI; if ($q->param('foo')) { #do stuff if has stuff in field }else { print $q->redirect(''); }
    the redirect goes back to your original html page. Make sure you don't print anything to the browser before the if to make the redirect work.

    if ($q->param('foo')) { #do stuff if has stuff in field }else { my $bar = $q->param('bar'); #should test this too. print $q->header; print "foo was empty please try again"; print "your html stuff here again"; #this next line keeps the info already provided. print "<input type=text name=bar value=$bar>"; }

Re: Displaying an Error
by elusion (Curate) on Jul 11, 2000 at 18:48 UTC
    I don't know about the possibilities of doing this in Perl, but Russ is right, you can do it in JavaScript, and quite easily too. If they don't filll out an area a little pop-up window will tell them that they need to fill it out. It'll be almost instantaneous as well. If you want to know how, just post a reply to this message and I'll write you up a little script.

    p u n k k i d

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://21902]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2023-10-01 22:53 GMT
Find Nodes?
    Voting Booth?

    No recent polls found