jdtoronto has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed Monks,

But for once the unanticipated behaviour is actually very useful! I was working on this method from my CGI::Application based webapp when I got interupted. Without thinking I ran the ocde and it did what I need. But I new I hadn't used the $form->output method to get the final HTML fragment for the form, which I was then going to pass through HTML::FillInForm. It turns out that passing \$form to HTML::FillInForm got me the results I wanted anyway - BEFORE I had parsed the template.

Here is the code fragment, it works and for that I am grateful, but I am not sure why! Can somebody help me understand please?

sub en_display { # Display 'full signup or enroll' form my $self = shift; my $errs = shift; my $form_output =''; my $sess = $self->param('up_session'); my %data = ''; my $page = $self->load_tmpl('gila/index.html'); my $form = $self->load_tmpl('ap_enroll.html', die_on_bad_params => + 0); # If _IS_USER is present and _IS_REGISTERED is set then we have pa +rtial data in the DB. if ( $sess->param('_IS_USER') && $sess->param('_IS_REGISTERED') && + !ref $errs ) { my $obj = AppSys::User->search( 'upusername' => $sess->param(' +_IS_USER')); while ( my $usr = $obj->next ) { foreach ( $usr->columns ) { $data{$_} = $usr->$_; } } # Get partial data into form, add to page and output my $fif = HTML::FillInForm->new(); $fif->fill(scalarref => \$form, fdat => \%data); $page->param('form_text' => $form->output()); return $page->output(); } elsif ( ref $errs ) { # If there are errors then D::FV has handled HTML stuff $form->param($errs); $page->param('form_text' => $form->output()); return $page->output(); } else { # No partial, no errors, just output blank form $page->param('form_text' => $form->output()); return $page->output(); } }
jdtoronto

Replies are listed 'Best First'.
Re: Unexpected behaviour in HTML::FillInForm
by cees (Curate) on Dec 21, 2003 at 16:26 UTC

    I don't think it does what you think it does...

    There is a small bug in your program. You do not capture the results of the ->fill call, hence the form is not being filled as you think. What you are seeing is probably the browser remembering what values you had filled in on a previous view of the page. If you check the page source I will bet that the form fields do not have value= attributes.

    - Cees

      Cees,

      Your are indeed correct! I was working away late at night and suddenly it seemed to work. But in fact it is an artifact of Mozilla's default form fill-in, as far as I can tell. When I checked it again on Konqueror and IE, and even Mozilla Firebird, it behaved as I thought it would - i.e. no filled in fields.

      I now have it parsing the form templater first, then filling it in, then dragging that into the final page and outputting it.

      Do you know if it is possible to force the browser not to remember the previous view?

      jdtoronto

        Do you know if it is possible to force the browser not to remember the previous view?

        This is speculation, and I don't know if it will work for all browsers, but if you explicitly add the 'value' attribute to each of your form elements then the browser should not use it's own values to prefill the form. If you want the form element to be blank then add value="" (obviously it will vary for other input types like select and textarea but the idea is the same).

        But this is all browser dependant, and hence out of control of the developer. Most browsers will allow you to disable the form filling features, but it is up to the end user to enable/disable the feature.

        - Cees