Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

HTML::FillInForm vs. checked by default checkboxes

by kappa (Chaplain)
on Feb 18, 2009 at 18:29 UTC ( [id://744840]=perlquestion: print w/replies, xml ) Need Help??

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

Good day to all!

There is an old HTML problem -- browsers do not send anything about unchecked checkboxes when submitting forms. How do you people usually use HTML::FillInForm to uncheck checkboxes which default to checked state?

Example:

<form> <input type=checkbox name=c checked> </form>
Suppose, I want to refill this form using HTML::FillInForm after user submitted the form. She unchecked the checkbox. To repeat unchecking the checkbox I need to pass c => 0 to fill() but browsers in their eternal wisdom do not send me anything about the checkbox so my code now needs knowledge that there is such a control on the form.

I've faced the issue ten or more times and always used some hacks with enumerating all checkboxes in a list and then generating pairs to pass to fill(). Are there cleaner ways?

--kap

Replies are listed 'Best First'.
Re: HTML::FillInForm vs. checked by default checkboxes
by bradcathey (Prior) on Feb 18, 2009 at 19:32 UTC

    I've been using HTML::FillInForm for ages now, but only in conjunction with HTML::Template and the cool plug-ing that comes with CGI::Application. Anyway, pulling from the docs:

    my $output = HTML::FillInForm->fill( \$html, \%fifvalues);

    If look at the above, note 3 main concepts:

    1. You need your HTML in a variable* (e.g., $html built by hand, CGI, or HTML::Template in your Perl script).
    2. You need the form value(s) in a variable (I always use a hash ref because I'm always pulling from a database, e.g., $fifvalues->{'gender' => 'male'}) assuming your radio button is named "gender" and one of the values is "male".
    3. Then you will need to print the $output, e.g., print "Content-type: text/html\n\n"; print $output;

    So, forget checked, it will be done for you. But just try it, that's how I learned.

    *Update: You can just reference an actual static html page with a form, negating the need to build it with the script.

    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
      Well, thanks, but I need checkboxes checked by default in HTML source.
      --kap

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-04-19 09:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found