[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-AnyPerl] Checkbox CGI



At 5:30 PM 6/20/00, EaTrom wrote:
>I'm trying to "read" a series of checkboxes (one per row) and perform an
>operation on each row depending on the state of the checkbox. Something
>along the line of:

[snip]

>what happens is that I can check the checkboxes, and on calling the cgi,
>it results in parameter like: "?xt2=yes" but on process_item the box is
>not checked. the print statement in process_item displays "xt2 == " so
>for some reason, the param is being lost.
>
>any assist?? or am I going about this all wrong??

Didn't study your code, but in the bigger picture, this is Not Your 
Fault. You're dealing with browser behavior: if a checkbox is checked 
when a form is submitted, the browser returns 'checkboxname=on', but 
nothing is returned for that checkbox if not checked. That is, 
there's no 'checkboxname=off' or 'checkboxname=' returned.

So, to safely handle the data coming in, your script can't rely 
purely on the name=value sets returned to it by the browser. You'll 
need to judge whether to take further steps. Maybe it doesn't matter, 
but with automated data handling one generally wants some value for 
every field, even if '' or null.

Case 1: If you are the creator of the web page with the form, then 
you can give your script a list of expected fields to process; and 
your script can know what to do if nothing comes in for a particular 
checkbox field.

Case 2: If your script must handle input from a form whose 
composition you don't control, then require the form to include a 
hidden field with the list of field names corresponding to the fields 
to be processed by the script.

In Case 1, if you don't need flexibility to easily change the HTML 
form and its fields, then 'hard code' the field names into the 
script. In both cases the best approach is making the list of fields 
external to the processing code.

Both cases also show why the best strategy for _any_ form-processing 
CGI is to have the script generate the HTML form from the git-go; 
that way the script always 'knows' what's coming.

Finally, if you use CGI.pm to power your scripts, its built-in field 
handling Does the Right Thing when you ask it for the value of a 
checkbox that wasn't checked.

Post-finally, this thread should continue on macperl-webcgi 
<macperl-webcgi@macperl.org>, rather than macperl-anyperl.

HTH

-- 

- Bruce

__Bruce_Van_Allen___bva@cruzio.com__Santa_Cruz_CA__

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org