http://qs1969.pair.com?node_id=1179356

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

Hi Monks,

Although I am grateful to still have hair remaining, I am pulling it out over an ostensibly simple CGI program I am trying to modify.

The interface keeps getting hit by bots and this results in cleanup time for yours truly -- so I was asked to put a simple CAPTCHA-type interface on this ca. 2000 or so CGI page.

I'm using the Authen::Captcha module to do this.

When the user is facing the front page s/he is asked to pick from a series of radio buttons - this is collected in a parameter 'CategoryRequest'. If this param is set, the program goes off and creates a new captcha object, then sends the user off to a page where this is displayed and a response is requested. Here's the code for that part, since it's the part causing me the headache:

sub getUserEntry { print header( "text/html" ), start_html( "User Validation" ), $header, h3( "Entry Validation" ), start_form, hr, p("Please enter the characters in the image at the bottom of t +he page"), textfield( -name => "UserEntry", -size => 15 ), br, br, submit( -name => "CodeValidation", -value => " Enter the Code " ), br, br, hr; print end_form; print "\<img src=\"./$www_output_dir/$md5sum.png\"\>"; print $footer; print end_html; return; }

... I'm expecting that sub to return to where I came from with the 'UserEntry' param filled in, so I can first validate the response and then make decisions based on the result ...

... but instead of waiting for the submit button to be pressed and the parameter to be duly defined, the program just swoops over or through the subroutine (whether I return things explicitly from it or not), assumes param( 'UserEntry' ) is empty, and displays both the UserEntry page along with an error page ("You haven't entered anything!") underneath it together in the same lump of html.

Why does this 'fall-through' happen? The logic I'm employing is as follows:

If the param( 'CategoryRequest' ) exists: create the captcha; get the user's response; If the user's response exists: <-- but this is never true check it against the real answer; do other things based on results of check

How do I get the UserEntry section to 'wait' for the user to enter something?

This feels like a far more basic question than I should have to be asking at this point in my learning, but ... here it is.

Thanks,

Glenn