CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Another Prject

 



SirAnvil
Deleted

Dec 17, 2000, 11:15 AM

Post #1 of 5 (721 views)
Another Prject Can't Post

Okay, I have a form that submits data to a .cgi. (duh)
use decided "I don't wanna answer that silly question". How do I make the perl program to send the back back to them with a little note saying "Hey dummy, answer ALL the questions"

?



japhy
Enthusiast

Dec 17, 2000, 12:46 PM

Post #2 of 5 (717 views)
Re: Another Prject [In reply to] Can't Post

If you find a form field that has an empty value, tell the user to go back and fill all the values in. Without seeing the specific code, I can't give you specific code to use, but you should be able to come up with the logic required.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


cir
Novice

Dec 17, 2000, 1:12 PM

Post #3 of 5 (713 views)
Re: Another Prject [In reply to] Can't Post

You could use something like
&error("Dummy, answer all the questions!") if(!$value);

Where $value is the var with the input that is required.

Also you's have to create the sub error. It could go something like:


Code
sub error { 
print "$_[0]";
exit;
}

Then if you run it and don't enter the info for $value you'll get the message "Dummy, answer all the questions!"

http://cirw.cjb.net
http://cbible.cjb.net
http://gmail.cjb.net

(This post was edited by japhy on Dec 17, 2000, 12:13 PM)


SirAnvil
Deleted

Dec 17, 2000, 3:33 PM

Post #4 of 5 (707 views)
Re: Another Prject [In reply to] Can't Post

I tried your suggestion and my results were not too bad.

&error("Please fill all required fields") if(!$name);

sub error {
print "$_[0]";
exit;
}

when the field name $name was filled with something the script continued on as normal. This is a good. However if I leave it blank I get
malformed header from script. Bad header=Please fill in all required

Gotta love lynx. Better errors. Anyway, I'm thinking since when the value was filled it did not return and error in the sub routine. When it was false .... was it the 'exit' command that halted it in it's tracks?



japhy
Enthusiast

Dec 17, 2000, 4:17 PM

Post #5 of 5 (705 views)
Re: Another Prject [In reply to] Can't Post

The problem is that the error message was printed before you sent the proper HTTP headers. Try changing the error function to:


Code
sub error { 
print "Content-type: text/html\n\n<b>Error:</b> $_[0]";
exit;
}

Or, better yet, use the CGI::Carp module to get the errors reported easily to both the browser and the error log:


Code
use CGI::Carp 'fatalsToBrowser'; 

# then use something like
die "please fill in the field 'name'\n" if not $fields{name};


Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives