[html-formfu] Date field and rendering a hidden field

Carl Franks fireartist at gmail.com
Mon Feb 25 08:56:57 GMT 2008


On 24/02/2008, Zbigniew Lukasiak <zzbbyy at gmail.com> wrote:
> On Wed, Feb 20, 2008 at 12:00 PM, Carl Franks <fireartist at gmail.com> wrote:
>  > On 15/02/2008, Zbigniew Lukasiak <zzbbyy at gmail.com> wrote:
>  >  > This looks quite weird.  When I render my form the hidden field does
>  >  > not get it's value.
>  >  >
>  >  > Here is the code:
>  >  >
>  >  > use strict;
>  >  > use warnings;
>  >  >
>  >  > use HTML::FormFu;
>  >  >
>  >  > my $form = HTML::FormFu->new;
>  >  > $form->load_config_file( 'e.yml' );
>  >  > $form->process( { first_instance_date_year => 2008 } );
>  >  > my $ind = $form->get_all_element( { name => 'event_indicator' } );
>  >  > $ind->default( 1 );
>  >  > warn $ind->value;
>  >  > warn $ind->render;
>  >  > warn $ind->value;
>  >  >
>  >  > __OUTPUT__
>  >  > 1 at form.t line 11.
>  >  > <input name="event_indicator" type="hidden" value="" /> at form.t line 12.
>  >  > 1 at form.t line 13.
>  >  >
>  >  > So it looks that the hidden field does have the value - but it is not
>  >  > printed out when rendering. And it happens only after processing the
>  >  > Date element.
>  >
>  >  This is the expected behaviour.
>  >
>  >  default() is only used if the form hasn't been submitted.
>  >
>  >  In this case, you need to set $hidden->retain_default(1)
>
>
> Hmm -  is there any theory behind that?  I cannot see any reason why
>  you should not be able to change some form value after it's been
>  submitted.  What am I missing?

default() is only intended to provide default values, prior to any submission.

Try changing the code to make fields use the default value if none was
submitted, and you'll start to get a lot of test failures!
You'd need to make it know somehow that you set default() *after*
calling process(), and that's the value you really want to use - but
that's no good, as we're moving towards making it mandatory that
nothing that could change the form is called between process() and
render().

However - I initially forgot about add_valid() - that should do
exactly what you want...

    $form->process;
    $form->add_valid( event_indicator => 1 );
    $form->render;

Carl



More information about the HTML-FormFu mailing list