[html-formfu] get_element problem

Carl Franks fireartist at gmail.com
Fri Oct 31 13:09:46 GMT 2008


2008/10/31 Dermot <paikkos at googlemail.com>:
> Hi,
>
> I struggle with the get_element method and in the past have fallen
> back on the get_all_elements method. Perhaps someone can spot where I
> am going wrong. In the snippets below I always receive an "Can't call
> method "options" on an undefined" value error
>
> Is there something wrong with the snippet/yml file below?

several things :)

> ...
>  else {
>    my @types = keys %fileTypes;
>    $c->log->debug("Types ",join ', ', @types);
>    my $select = $form->get_elements( {name => 'filetypes'});
>    $c->log->debug("Select is ", $select);
>    $select->options(\@types);
>    $c->stash->{template} = 'files/foo.tt2';
>  }

You're using auto_fieldset - so get_elements() will only return the
top-level fieldset - nothing else.

You're calling get_elements - note the "s" on the end - that would
return an arrayref, which isn't what you want.

If you're wanting a field - which you do - then forget all about
get_element(s) / get_all_element(s) - just use either get_field() or
get_fields()

get_field() returns a single field object
get_fields() returns an arrayref of field objects

Cheers,
Carl



More information about the HTML-FormFu mailing list