Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Accessing CGI::FormBuilder text in HTML::Template

by hesco (Deacon)
on Jun 25, 2009 at 10:38 UTC ( [id://774661]=perlquestion: print w/replies, xml ) Need Help??

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

The perldoc for HTML::FormBuilder reports that its constructor (and its ->render() method as well) will accept a text parameter, explained as:

my $form = CGI::FormBuilder->new( text => $text, # printed above form ); text => $text This is text that is included below the title but above the actual for +m. Useful if you want to say something simple like "Contact $adm for +more help", but if you want lots of text check out the "template" opt +ion above.
I'm trying to use this to pass along validation errors. However those error reports, while they seem to show up when Data::Dump'd to STDERR, never make it through the HTML::Template to the browser. I can find nothing in the documents suggesting how to pass that along. Can anyone please advise me of how to make that happen?

I've tried <tmpl_var field-text>, though that did not seem right. I also tried tmpl_var name=text>. But these are simply silly wild-eye'd guesses. A review of the module code gave me no clues (although $self->{'messages'} got me momentarily excited that I might have been on to something useful, it turned out to be about choosing a locale for translation instead).

Seems to me that feeding custom data validation error messages into the constructor would be a useful feature to add to the CGI::FormBuilder mix, but for the moment, I only need to figure out how to hand off my hand-rolled to the HTML::Template I'm using.

Any advice is appreciated.

-- Hugh

UPDATE:

Well, I hacked around it, TIMTOWTDI, I guess. I embedded a replacement token in my template, generated the html from the template and then used $html =~ s/VALIDATION_ERRORS/$text/; and kept on moving. Even so, I think it would be a sweet addition to CGI::FormBuilder to permit the definition of validation error strings in the validate => {} hashref fed to the constructor. Though not sweet enough an addition to justify being distracted from the critical path for launch of this current project.

Oh, btw, wfsp, having reread the perldoc for CGI::FormBuilder::Messages, I believe that is a tool for translation and localization, not for the purpose I'm working on right now. Though I remain curious about how those messages are used, since I have not seen any evidence of them on validation errors.

if( $lal && $lol ) { $life++; }

Replies are listed 'Best First'.
Re: Accessing CGI::FormBuilder text in HTML::Template
by wfsp (Abbot) on Jun 25, 2009 at 11:24 UTC
    In the docs for CGI::FormBuilder::Messages is
    my $form = CGI::FormBuilder->new( messages => { js_invalid_start => '%s error(s) were found in your form:\n', js_invalid_end => 'Fix these fields and try again!', js_invalid_select => '- Choose an option from the "%s" list\n', } );
    It appears to be more than just choosing a locale. There is a list of available messages and their defaults.

    hth

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://774661]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-20 03:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found