Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Multi-form pages with CGI::FormBuilder and HTML::Template

by hesco (Deacon)
on Jan 25, 2009 at 23:19 UTC ( [id://738842]=perlquestion: print w/replies, xml ) Need Help??

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

Hey folks:

I'm trying to wrap my head around how to integrate HTML::Template and CGI::FormBuilder to create a dashboard page which will include multiple components, charts and forms.

Right now my dashboard.cgi page includes an invocation of a module I've written reading:

$html .= $ymd->render_schedule_job_form();
The ->render_schedule_job_form() method use CGI::FormBuilder to collect and process some data. My $form object's constructor includes a:

template => $self->{'cfg'}->param("tmpl.tmpl_ScheduleJob"),
And it produces javascript which gets put in the header of the http response.

So far, so good.

Now to complicate things, my base template for the dashboard page is filled with <tmpl_include tags, some which also offer forms built with CGI::FormBuilder. Now what happens when they start competing over who gets to send the header and the javascript.

I'm having trouble understanding how to write this in a way which would avoid such conflicts. Any advise or pointers would be appreciated.

-- Hugh

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

Replies are listed 'Best First'.
Re: Multi-form pages with CGI::FormBuilder and HTML::Template
by Anonymous Monk on Jan 26, 2009 at 00:51 UTC
    Now what happens when they start competing over who gets to send the header and the javascript.
    HTML::Template doesn't deal with headers, and it realy doesn't matter for javascript.
      I believe the post is about HTML <head> section of the document. There are a number of CGI::FormBuilder methods to manipulate how javascript is handled, but I'm not sure there is anything about outputting javascript that won't conflict with other javascript that has previously been generated. For example, what happens if you have two forms and they both output functions with the same name? I have no idea.

      Probably the easiest thing is to just disable javascript output for one of those forms. Submission should get checked again anyway on the server side. From the docs on the CGI::FormBuilder constructor:

      javascript => 0 | 1 If set to 1, JavaScript is generated in addition to HTML, the default setting.
      You can also look at the template section and write your own template (then at least you can control where the javascript goes, if anywhere).
Re: Multi-form pages with CGI::FormBuilder and HTML::Template
by dsheroh (Monsignor) on Jan 26, 2009 at 11:46 UTC
    <tmpl_include> just processes the other template and inserts the resulting text in place of the <tmpl_include> tag. So, if you're including component templates which generate <head> sections, then you'll get <head>s in the middle of your <body>, which is probably not the desired behaviour.

    I tend to get around this by having a container template which defines headers, footers, navigation elements, etc. and then content templates to generate each piece of the actual page. This gives me the freedom to mix and match the content templates however I like without creating conflicts, then insert the result into the <body> of the container template. (It also has the advantage of only defining the header, footer, etc. in one place, so consistency from page to page is assured and, if it does need to change, there's only one place it needs to be changed.) Having never used CGI::FormBuilder, though, I have no idea how/if it might fit into this sort of scheme.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-18 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found