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

Greetings great sages

I have a question about form action using TT2 and FB.

Here's the details.

I have a an FB-based script using a TT2 template. The template sets the baseurl meta tag and creates the initial form using this instantion of an FB object

85 my $form = CGI::FormBuilder->new( 86 template => { 87 type=> 'TT2', 88 template => 'contact.tt', 89 variable => 'contact' }, 90 name => 'contactform', 91 id => 'contactform', 92 fields => \@formfields , 93 method => 'post', 94 );

If I use this, I get The requested URL /<scriptname> was not found on this server. error message because, upon form post, there is an attempt to load <baseurl>/<scriptname> and not <baseurl>/cgi/<scriptname>

I have also tried

  1. action => '<baseurl>'/cgi/'scriptname' in the script - Result: an HTTP 500 Internal Server Error with the script url still intact
  2. action => './cgi/<scriptname>' - Result: gives some errors in the cgi script and the url still intact
  3. action => './<scriptname>' - Result: the error The requested URL /contact.cgi was not found on this server.
  4. setting the baseurl to '<original baseurl>/cgi/' in the template - Result: promptly lose my stylesheets and other constant site data based on baseurl

Okay, I have to debug my script some, and I will be looking for something to help with automatic form submission and testing.

However, I have found that the form action as in 0 (accept FB's default) and 3 don't give the desired result of form post to the original form url. Method 2 gives the desired result, and I'm still out with the jury on method 1.

I can understand why method 3 fails. The scriptname is concatenated to the baseurl and this appears to be what happens with FB's default too.

I'm using method 2 because it works

I would like to know if there is a way to avoid mentioning the scriptname in the instantion of the FB object when using a directory structure on cgi scripts or would it be better to not have that directory structure? Is this the tradeoff?

Replies are listed 'Best First'.
Re: Form action with TT2 and FB v3.03
by Anonymous Monk on Jul 25, 2008 at 14:00 UTC
    If the default doesn't work, its a bug in CGI::FormBuilder. Should use $ENV{SCRIPT_NAME} or $cgi->script_name, guaranteed to be correct.

      As the script is on Debian stable it's not the most up-to-date version of FB - which is at v3.05. I couldn't see anything in the active or resolved bug lists that appeared to relate to this.

      I explicitly set action => $ENV{SCRIPT_NAME}, and that returns action="/cgi/<scriptname> in the form.

      I have now updated CGI.pm and CGI::FormBuilder and the problem seems to still exist when using a default undeclared action at the later versions.

      UpdateMy Perl isn't good enough to understand FormBuilder.pm yet but I've filed a bug with the workaround you suggested

      Thank you for your help