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

J. Bobby Lopez jbl at jbldata.com
Fri Nov 4 19:24:19 GMT 2011


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?

On Fri, Nov 4, 2011 at 3:16 PM, J. Bobby Lopez <jbl at jbldata.com> wrote:
> Hello Carl,
>
> Thank-you for responding.
>
> How would this work with multi-valued selects?  Can default_values()
> still be used to show which items are selected by default, or would
> default_values have to be avoided altogether for multi-value selects?
>
> On Fri, Nov 4, 2011 at 2:48 PM, Carl Franks <fireartist at gmail.com> wrote:
>> On 4 November 2011 17:41, J. Bobby Lopez <bobby.lopez at gmail.com> wrote:
>>> Hello,
>>>
>>> I'm trying to understand the data-structure required to populate a
>>> form with 'select' element values (options).
>>>
>>> When I dump (Data::Dumper) the FormFu object, I see that the structure
>>> looks similar to the following:
>>>
>>>
>>> 'name' => 'EmailDL',
>>>
>>> '_options' => [
>>>
>>>              {
>>>
>>>                'label_attributes' => {},
>>>
>>>                'value' => 'm',
>>>
>>>                'container_attributes' => {},
>>>
>>>                'label' => 'Male',
>>>
>>>                'attributes' => {}
>>>
>>>              },
>>>
>>>              {
>>>
>>>                'label_attributes' => {},
>>>
>>>                'value' => 'f',
>>>
>>>                'container_attributes' => {},
>>>
>>>                'label' => 'Female',
>>>
>>>                'attributes' => {}
>>>
>>>              }
>>>
>>>            ],
>>>
>>> Seeing this, I figured that the way to structure $form_input (being
>>> that $form_input = \%cgivars) would be something like the following:
>>>
>>>          'Firstname' => 'Faisal',
>>>          'EmailDL' => [
>>>                         {
>>>                           'value' => 'myvalue',
>>>                           'label' => 'mylabel'
>>>                         }
>>>                       ],
>>>
>>> However this doesn't seem to work.  I've found that structuring
>>> $form_input correctly, and then issuing a
>>> $fu->default_values($form_input) to be simple and effective, except in
>>> this instance when I'm trying to include the select/options
>>> sub-structure.
>>>
>>> So the question is:  How should I structure 'EmailDL' above to
>>> correctly populate 'select' options when doing
>>> $fu->default_values($form_input) or $fu->process($form_input) ?
>>
>> Hi,
>> You can't use default_values() to populate a Select element.
>> You need to use options() or values().
>> You can then call default_values() to state which select item will be
>> selected by default when the form is first displayed.
>>
>> See these docs:
>> http://search.cpan.org/~perler/HTML-FormFu-0.09005/lib/HTML/FormFu/Role/Element/Group.pm#options
>> http://search.cpan.org/~perler/HTML-FormFu-0.09005/lib/HTML/FormFu/Role/Element/Group.pm#values
>> http://search.cpan.org/~perler/HTML-FormFu-0.09005/lib/HTML/FormFu.pm#default_values
>>
>> Hope this helps,
>> 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