[html-formfu] get_element returns undef
Carl Franks
fireartist at gmail.com
Wed Sep 17 11:24:14 BST 2008
2008/9/17 goetz <devel at helektra.de>:
> Hallo,
>
> I trie to use get_element with no success.
>
> The debug output is always undef.
>
> When I use get_field or get_all_element I get the correct
> output.
>
>
> Any hint?
>
>
> Her are the details:
>
> in the config file:
>
> - type: Select
> name: name
> label: name
>
>
> in my controler:
>
> my $test = $form->get_element({ type => 'Select'}); # undef !!!!!!!
> my $test01= $form->get_elements({type => 'Select'});
> my $field = $form->get_field(name => 'name');
> my $select= $form->get_all_element({type => 'Select'});
As that's only a snippet of the form config - I'm going to take a
guess that you're either using auto_fieldset() - or the Select menu is
nested by some other means, such as an explicit block.
In which case, this behaviour is correct.
$form->get_element() only returns direct children of the form object.
If the Select element is nested within a fieldset or block, it'll
never be returned.
$form->get_elements() also won't return nested children, but it won't
be undef, it'll just return an empty arrayref.
$form->get_all_elements() does a recursive search, so it'll return the
Select element.
$form->get_field() also does a recursive search, so that'll work.
If you're after a field, then get_field() / get_fields() are probably best.
Cheers,
Carl
More information about the HTML-FormFu
mailing list