[html-formfu] Populating $form_input with 'select' element options?

J. Bobby Lopez jbl at jbldata.com
Mon Nov 7 18:18:53 GMT 2011


Thanks very much for this Carl, your insight pointed me in the right
direction.  It seems there are some caveats in the way I've been
reading CGI vars which affect multi-valued parameters.

>From http://perldoc.perl.org/CGI.html
--
When using this, the thing you must watch out for are multivalued CGI
parameters. Because a hash cannot distinguish between scalar and list
context, multivalued parameters will be returned as a packed string,
separated by the "\0" (null) character. You must split this packed
string in order to get at the individual values. This is the
convention introduced long ago by Steve Brenner in his cgi-lib.pl
module for Perl version 4.
--

So it may in fact be possible to use $form_input to populate a formfu
object with multi-valued parameters, as long as the packed string with
"\0" dealt with.

Still, I may just do it they way you've suggested in order to keep
things clear and obvious.

-Bobby


On Sat, Nov 5, 2011 at 6:35 PM, Carl Franks <fireartist at gmail.com> wrote:
> On 4 November 2011 19:24, J. Bobby Lopez <jbl at jbldata.com> wrote:
>> I also see that when I dump %cgivars after submitting a form with
>> multiple values selected in a 'select' element, that the values become
>> concatenated.
>>
>> E.g (FormFu yml):
>>
>>    - type: Select
>>      name: EmailDL
>>      label: 'Subscribed Lists:'
>>      options:
>>        - [ 'male', 'Male' ]
>>        - [ 'female', 'Female' ]
>>
>>
>> And resulting params (%cgivars):
>>   {
>>          ...,
>>          'EmailDL' => 'malefemale',
>>          ...,
>>   }
>>
>>
>> So I'm not sure how FormFu would deal with multi-valued selects in general?
>
> Hi,
> I've just committed test files checking that multi-value selects work.
> Setting default with $field->default(\@values), and submitting multiple values:
> https://github.com/fireartist/HTML-FormFu/blob/master/t/elements/select_multi_value.t
> Setting default with $form->default_values({ name => \@values });
> https://github.com/fireartist/HTML-FormFu/blob/master/t/elements/select_multi_default_values.t
> Everything seems to work as expected.
>
> I'm not sure where your %cgivars comes from - and whether you're using
> CGI, CGI::Simple or Catalyst?
>
> Carl
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>



More information about the HTML-FormFu mailing list