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

I have a group of checkboxes on my form and when I print to my email $choices it's not printing all the choices they selected! :(

How can I store and print every checkbox that they checked?

Replies are listed 'Best First'.
Re: printing checkboxes from a form
by sh1tn (Priest) on Apr 10, 2005 at 00:36 UTC
      And the key is that you assign param to an array, not a scalar. If you assign it to a scalar you'll just get the first checkbox in the group that was selected.

      The gory details of context are explained in perlsyn, I also touched on it at Arrays are not lists.

Re: printing checkboxes from a form
by jhourcle (Prior) on Apr 10, 2005 at 00:47 UTC

    This is one of those times when showing your code really helps, as we have no idea how you're pulling the data from the form.

    If you're using CGI, you'll want to make sure you use scalar context. If you're using CGI::Lite, you'll want to use get_multiple_values. If you're using something home grown... it's possible that you're not handling parsing the content or QUERY_STRING correctly. You can fix this by switching to using CGI, or show your code, so people can tell you what's going on.

Re: printing checkboxes from a form
by tlm (Prior) on Apr 10, 2005 at 00:47 UTC

    Are you are using the CGI.pm module? If so, I gather that you are collecting the return value of param in this scalar $choices, and that's the problem. To get the values of all the selected checkboxes you need to collect them in an array, like this:

    my @checked = $q->param('checkboxes');

    the lowliest monk