in reply to Re^2: Formbuilder: generate id, that includes formname
in thread Formbuilder: generate id, that includes formname

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
<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_U +S"> <head> <title> </title> </head> <body bgcolor="white"> <h3> </h3> <!-- Generated by CGI::FormBuilder v3.0501 available from www.formbuil +der.org --> <form action="-" id="acctinfo" method="get" name="acctinfo"> <div id="acctinfo_state"><input id="_submitted_acctinfo" name="_submit +ted_acctinfo" type="hidden" value="1" /></div> <table id="acctinfo_body"> <tr id="acctinfo_fname_row" valign="top"> <td id="acctinfo_fname_label">First Name</td> <td id="acctinfo_fname_field"><input id="fname" name="fname" type="t +ext" /></td> </tr> <tr id="acctinfo_lname_row" valign="top"> <td id="acctinfo_lname_label">Last Name</td> <td id="acctinfo_lname_field"><input id="lname" name="lname" type="t +ext" /></td> </tr> <tr id="acctinfo_submit_row" valign="top"> <td align="center" colspan="2" id="acctinfo_submit_field"><input id= +"acctinfo_submit" name="_submit" type="submit" value="Submit" /></td> </tr> </table> </form> </body> </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);

Replies are listed 'Best First'.
Re^4: Formbuilder: generate id, that includes formname
by Wolfgang (Novice) on Oct 06, 2009 at 13:31 UTC
    You are right, that is want I want. Things are somewhat different though, because since I'm using catalyst I also have the .tt-Files (HTML) and the .fb (form definition) to consider.

    To make matters worse I'm working in an environment where the package ext (JS-Package) loads the html via ajax. JS inside of the html therefore will not be executed (in a consistent way, considering all browsers).

    Because I (want to) use the same perl construct in several html-templates the predefined js-functions have to be able to identify the correct formbuilder-element. Eventually I ended up with this solution:

    CGI::FormBuilder::Source::File lets me define an additional id, if I do so, formbuilder will use this and not create its own. That is true for the form element as well as for the input-elements.

    Even better, in the html-template I can ask the formbuilder input object for its id. The only minor flaw is, that the id of the form object can not be found this way

    So I have to enter that id in several files, which kind of bugs me and causes bugs ;-)

    Guess, I'll have to live with it

    Thanks anyway

      Guess, I'll have to live with it

      Nooooo! :) CGI::FormBuilder hasn't been updated since 02 Mar 2007, I say you take over, or fork the project :)