Marie Shvartsapel | 15 Mar 06:22
Favicon

HTML::Template + validation = strange behavior?

Hello,

I'm new to the FormBuilder and to this list, so please excuse me if this has
been discussed already.
I am trying to use HTML::Template template + validation functionality of the
FB. I turned off JavaScript and want to use server side validation only.

Let me describe the scenario in short: Form is displayed, submitted (with
blank fields), redisplayed with error messages, submitted again (again with
blank values). Now the fun part: All of my visible form elements get
doubled!

     Am I not using FB or template correctly or this is "a feature" of FB?

Ok, a little clarification - it seems to be happening when I leave the field
blank without trying to fill it in, just submit it again , whereas this
problem does not seem to occur when some other not-empty invalid value was
provided and left unchanged...
I agree that this is not very typical usage, but hey, you can overlook one
of the values if you are working with a long form.
I have created very simple test script to make sure nothing else gets in the
way.

You can test it for yourself here:
http://maries.thecsl.org/cgi-bin/clearinghouse/test.pl (see code below)

Another detail - I'm using "keepextras"set to 1. Not sure if this might be
related.

A little bonus question: Is my understanding correct that I have to
explicitly include "<tmpl_var error-name1>" into my template if I want error
messages to be displayed? Originally I thought that <tmpl_var field-name1>
will take care of error msgs for me....

Thanks in advance, I really hope to get this resolved...
-Marie.

Script code:
#!/usr/bin/perl
use strict;
use warnings;
use CGI::FormBuilder;
my $form=CGI::FormBuilder->new(
 fields => [qw(name1 name2)],
 method => 'post',
       template => 'temp.temp',
       validate => {
   name1=>'NAME',
   name2=>'NUM'
  },
 header=>1,
 keepextras=>1,
 javascript=>0
);
if ($form->submitted && $form->validate){
 print "Content-type: text/html\n\nThe submition is valid";
}else{
 print $form->render;
}

Template code:
<html>
<body>
<tmpl_var form-start>
Name<tmpl_var field-name1><tmpl_var error-name1><br>
Number<tmpl_var field-name2><tmpl_var error-name2><br>
<tmpl_var form-submit>
<tmpl_var form-end>
</body>
</html>


Gmane