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

Hi everybody, I'm looking for a way to have Formbuilder generate an id for each field, that contains the form name

I found some definitions in Util.pm (growname, idprefix) but could not locate the parts of the source code that may use this.

The documentation tells me, formbuilder will generate a compound id (formname + '_' + fieldname), the reality (for me) disagrees.

Anybody out there, who could help find the right way to tell formbuilder my intentions?

I'm using FormBuilder 3.0501, Catalyst, Template::Toolkit

Wolfgang

  • Comment on Formbuilder: generate id, that includes formname

Replies are listed 'Best First'.
Re: Formbuilder: generate id, that includes formname
by Anonymous Monk on Sep 30, 2009 at 08:26 UTC
    FormBuilder doesn't exist, are you talking about CGI::FormBuilder? CGI::FormBuilder does that if you specify a form name.

      CGI::Formbuilder was the one I talked about (which in my case was called by Catalyst::Controller::FormBuilder).

      the form-name is only used for the name of the form, not as an prefix for the name of the fields inside the form.

      if the prefixing works for you, can you show me some lines how you configure it to work?

      Wolfgang
        the form-name is only used for the name of the form, not as an prefix for the name of the fields inside the form

        I see, a misunderstanding. Documentation shows

        <tr id="${form}_${field}_row"> <td id="${form}_${field}_label">Label</td> <td id="${form}_${field}_input"><input tag></td> <td id="${form}_${field}_error">Error</td><!-- if invalid +--> </tr>
        And that matches my experience (s/_input/_field/), this code
        #!/usr/bin/perl -- use strict; use warnings; use CGI::FormBuilder; my $form = CGI::FormBuilder->new( name => 'acctinfo'); $form->field(name => 'fname', label => 'First Name'); $form->field(name => 'lname', label => 'Last Name'); print $form->render(header => 1);
        produces this html It seems you want
        #!/usr/bin/perl -- use strict; use warnings; use CGI::FormBuilder; my $form = CGI::FormBuilder->new( name => 'acctinfo'); $form->field(name => 'acctinfo_fname', label => 'First Name'); $form->field(name => 'acctinfo_lname', label => 'Last Name'); print $form->render(header => 1);