[html-formfu] how to populate a form from a hash?

Mario Minati mario.minati at googlemail.com
Wed Sep 19 18:16:18 GMT 2007


On Wednesday 19 September 2007 17:34:25 Andreas Borowski wrote:
> Hi,
>
> is there a method to provide default values for each element in a form
> from a hash? Something like:
>  $form->set_default_values(
>        { street => 'Bakerstreet',
>          city => 'London'}
>  );
>
> So far, I tried $form->process( %hash ). This fills in the values into
> the fields, but also creates unwanted error-messages for failed
> constraints.

You can use something like te following before calling 'process':
$hashref = { street => 'Bakerstreet', city => 'London'};
map { $form->get_field( $_ )->default( $hashref->{$_} ) } keys $hashref;

Greets,
Mario



More information about the HTML-FormFu mailing list