On Thu, 17 Jan 2002 03:21, Mark Stosberg wrote:
> Jesse Erlbaum wrote:
> > Since it is unlikely that a particular button will change its
destination
> > run-mode, statically defining it in a template is a very valid
solution.
>
> This is what I usually do as well. I find defining the HTML elements
> directly in HTML makes them easier to develop and debug. I only really
> use the CGI.pm HTML generation features for some of the non-text box
> form elements, particularly the pop up menus.
>
> Often HTML::FillInForm will handle re-filling forms for me without even
> messing with CGI.pm for that case.
I use HTML::FillInForm as well, but have found that you need to be careful
with your run-modes when using HTML::FillInForm. Even if you statically
add your runmodes to your templates, HTML::FillInForm will 'rewrite' your
hidden fields, including the runmode if the runmode was part of the CGI
query object. This is only really a problem if you have multiple forms on
your page that submit to different runmodes.
What I do to solve this is the following:
I have a Base.pm for each application that inherits from CGI::Application
and sets up a bunch of helper functions and any other common functions,
including the following wrapper around HTML::FillInForm.
sub form {
my $self = shift;
my $htmlref = shift;
# Create the HTML::FillInForm object unless we already have it
my $self->{'_form'} ||= new HTML::FillInForm();
# Save and delete the runmode from the CGI query
my $rm = $self->query->param('rm');
$self->query->delete('rm');
# Fill the forms on the page
return $self->{'_form'}->fill(
scalarref => $htmlref,
fobject => $self->query()
);
# Restore the runmode parameter (must always statically
# define runmodes in the templates)
$self->query->param(-name => 'rm', -value => $rm);
}
Then in my runmode I can call the following code
my $html = $t->output();
return $self->form(\$html);
This is done on two lines so that we can pass the HTML page by reference
to save a bit of memory.
I have similar wrapper functions for Data::FormValidator and any other
modules that my runmodes often use. It makes the runmodes that much
smaller and easier to read.
I'd be interested to hear what others have done to make their applications
cleaner and more structured...
Cees
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]