[html-formfu] Taking default value when not supplied in query

Wicked bits wickedbits at gmail.com
Sat Oct 9 16:10:13 GMT 2010


When FormFu processes a query that contains only some of the defined fields,
how can the fields that don't appear in the query have their default
value(s) in $form->params?


#!/usr/bin/perl

use strict;
use HTML::FormFu;
use Data::Dumper;

my $form =3D HTML::FormFu->new;

$form->indicator('foo');  # only foo is required to be considered submitted

# required field
$form->element({
name           =3D> 'foo',
 constraints    =3D> 'Required'
});

# optional field - when bar is not supplied, should use its default
$form->element({
name           =3D> 'bar',
 type           =3D> 'Select',
 default        =3D> 'b',
 retain_default =3D> 1,
 values         =3D> [qw/ a b c /],
});

# bar is not supplied as part of query
$form->process({
 foo =3D> 'a'
});

print Dumper( $form->params );

# output:

# $VAR1 =3D {
#    'foo' =3D> 'a'
# };


# desired output:

# $VAR1 =3D {
#    'foo' =3D> 'a',
#    'bar' =3D> 'b'
# };
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20101009/ef=
ea8e47/attachment.htm


More information about the HTML-FormFu mailing list