Home > Archive > PERL Beginners > March 2005 > HTML::Template help continues....
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
HTML::Template help continues....
|
|
| Mick I Hawkes 2005-03-30, 3:58 am |
| Hi all,
First off thanks to Charles and Offer for there help. Err, the spelling =
should have been the same :-)
Silly error, done in haste. Anyway I fixed it all up but it still =
doesn't work! :-(.
I sliced it up to a test page and played with it but I still can't get =
the darn thing working. Oh and Charles the code does have white space=20
I don't know why the mailer sent it that way. Fingers crossed that the =
code below comes out right!
Here is the test page:
<!-- test.tmpl.htm -->
<!-- This form must return a NAME attribute=3D'rm' with a VALUE =
attribute =3D
'mode_1 or 'mode_2' or 'mode_3'. -->
<html>
<head>
</head>
<body>
<form method=3D"post" action=3D"/cgi-bin/TestBed/test_main.cgi">
*Project:<input type=3D"text" size=3D"100" name=3D"html_projectname" =
value=3D"<TMPL_VAR NAME=3D"html_projectname">"><br>
*Date Listed:<input type=3D"text" size=3D"20" name=3D"HTML_DateListed" =
value=3D"<TMPL_VAR NAME=3D"HTML_DateListed">"><br>
*Resp. Officer:<input type=3D"text" size=3D"20" =
name=3D"HTML_RespOfficer" value=3D"<TMPL_VAR =
NAME=3D"HTML_RespOfficer">"><br>
Area Mgr:<input type=3D"text" size=3D"20" name=3D"HTML_AreaMgr" =
value=3D"<TMPL_VAR NAME=3D"HTML_AreaMgr">"><br>
Technology:<input type=3D"text" size=3D"20" name=3D"HTML_Technology" =
value=3D"<TMPL_VAR NAME=3D"HTML_Technology">"><br>
Priority:<input type=3D"text" size=3D"20" name=3D"HTML_Priority" =
value=3D"<TMPL_VAR NAME=3D"HTML_Priority">"><br>
Area:<input type=3D"text" size=3D"20" name=3D"HTML_Area" =
value=3D"<TMPL_VAR NAME=3D"HTML_Area">"><br>
status:<select name =3D"<TMPL_VAR NAME=3D"HTML_Status">">
<option value =3D "<TMPL_VAR NAME=3D"HTML_Status">" selected> =
<tmpl_var name=3D"HTML_Status">=20
<option value=3D"Open">Open=20
<option value=3D"Pending">Pending=20
<option value=3D"Closed">Closed=20
</select><br>
Fault Source:<input type=3D"text" size=3D"20" name=3D"HTML_FaultSource" =
value=3D"<TMPL_VAR NAME=3D"HTML_FaultSource">"><br>
Fault Source Contact:<input type=3D"text" size=3D"20" =
name=3D"HTML_FaultSourceContact" value=3D"<TMPL_VAR =
NAME=3D"HTML_FaultSourceContact">"><br>
<!--*Project Description:<textarea name=3D"HTML_ProjectDescription" =
rows=3D"4" cols=3D"100" wrap><tmpl_var =
name=3D"HTML_ProjectDescription"><br>
--> =20
<input type=3D"hidden" name=3D"caller" value=3D"editproject">
<input type=3D"hidden" name=3D"rm" value=3D"mode_5">
<input name=3D"submit" type=3D"submit" value=3D"Add Project">
<br>
* denotes a manditory field
</body>
</html>
All the code does is read in the data and then sent it back to the page. =
All the other textboxs work except for you know who!
Anyway here is the code that I process this with
sub insertproject
{
my $self =3D shift; # get the passed parameters.
my $q =3D $self->query(); # get acopy of the CGI object.
my $dbh =3D $self->param('mydbh'); # get the database handle.
## Construct the SQL Statement
# Get the values from the form.
# my $HTML_OCLRef =3D $q->param("HTML_OCLRef");
# my $HTML_ProjectID =3D $q->param("HTML_ProjectID");
my $HTML_RespOfficer=3D$q->param("HTML_RespOfficer")||undef;
my $HTML_ProjectName=3D$q->param("html_projectname")||undef;
my $HTML_DateListed=3D$q->param("HTML_DateListed")||undef;
my =
$HTML_ProjectDescription=3D$q->param("HTML_ProjectDescription")||undef;
my $HTML_Priority=3D$q->param("HTML_Priority")||undef;
my $HTML_Status=3D$q->param("HTML_Status");
my $HTML_AreaMgr=3D$q->param("HTML_AreaMgr")||undef;
my $HTML_Technology=3D$q->param("HTML_Technology")||undef;
my $HTML_Area=3D$q->param("HTML_Area")||undef;
my $HTML_FaultSource=3D$q->param("HTML_FaultSource")||undef;
my =
$HTML_FaultSourceContact=3D$q->param("HTML_FaultSourceContact")||undef;
#my $HTML_DateCompleted=3D$q->param("HTML_DateCompleted")||undef;
# Setup the template to use for the output.
my $template =3D $self->load_tmpl('test2.tmpl.htm');
#set up the data to give to the HTML template....
#$template->param(HTML_ProjectID =3D> $row->{ProjectID});
#$template->param(HTML_OCLRef =3D> $row->{OCLRef});
$template->param(HTML_RespOfficer =3D> $HTML_RespOfficer);
$template->param(HTML_ProjectName =3D> $HTML_ProjectName);
$template->param(HTML_DateListed =3D> $HTML_DateListed);
$template->param(HTML_ProjectDescription =3D> =
$HTML_ProjectDescription);
$template->param(HTML_Priority =3D> $HTML_Priority);
$template->param(HTML_Status =3D> $HTML_Status);
$template->param(HTML_AreaMgr =3D> $HTML_AreaMgr);
$template->param(HTML_Technology =3D> $HTML_Technology);
$template->param(HTML_Area =3D> $HTML_Area);
$template->param(HTML_FaultSource =3D> $HTML_FaultSource);
$template->param(HTML_FaultSourceContact =3D> =
$HTML_FaultSourceContact);
#$template->param(HTML_DateCompleted =3D> $HTML_DateCompleted);
# Output the template...
$template->output;
}
I don't see why this doesn't work, but I have been frustrated like this =
before with this type of code (HTML::Template) where code that should =
work just doesn't then all of a sudden it does! For now reason that I =
can see or duplicate! I'm starting to this is a really dodgy module.
Cheers
Mick
| |
| Charles K. Clarkson 2005-03-30, 3:58 am |
| Hawkes, Mick I <mailto:Michael.I.Hawkes@team.telstra.com> wrote:
: Here is the test page:
:
: <!-- test.tmpl.htm -->
: <!-- This form must return a NAME attribute='rm' with a VALUE
: attribute = 'mode_1 or 'mode_2' or 'mode_3'. -->
Oh, you're one of those no DOCTYPE people, huh. :)
: <html>
[snipped helpful code.
: status:<select name ="<TMPL_VAR NAME="HTML_Status">">
That should be:
status:<select name="HTML_Status">
: <option value = "<TMPL_VAR NAME="HTML_Status">" selected> <tmpl_var
name="HTML_Status">
That should be (note the missing spaces):
<option value="<TMPL_VAR NAME="HTML_Status">" selected><tmpl_var
name="HTML_Status">
Better:
<option value="<TMPL_VAR NAME="HTML_Status">" selected><tmpl_var
name="HTML_Status"></option>
: <br>
: * denotes a manditory field
:
The form never ends.
</form>
: </body>
: </html>
:
: All the code does is read in the data and then sent it back to the
: page. All the other textboxs work except for you know who!
:
: Anyway here is the code that I process this with
Please don't shoot the messenger, but you're doing a lot unneeded
typing. It looks like you are inside a CGI::Application script. All
you need to do is associate the query object to populate the form.
Read the HTML::Template docs for details.
sub insertproject {
my $self = shift;
# Setup the template to use for the output.
my $q = $self->query();
my $template = $self->load_tmpl( 'test2.tmpl.htm',
associate => $q,
die_on_bad_params => 0,
);
## Construct the SQL Statement and add results to template
# my $dbh = $self->param('mydbh');
# Output the template...
return $template->output;
}
: I don't see why this doesn't work, but I have been frustrated like
: this before with this type of code (HTML::Template) where code that
: should work just doesn't then all of a sudden it does! For no reason
: that I can see or duplicate! I'm starting to this is a really dodgy
: module.
The HTML::Template module is very well tested. The errors were in
the template, but I needed to testing to find the error. Had you
presented a way to test your problem, we could have helped you solve
it faster. I find many of my problems while constructing such a test
platform.
To test your code snippet I created a slightly altered form and a
module named foo.pm. With the changes above, things seem to be working
fine.
package foo;
use base 'CGI::Application';
use CGI::Carp 'fatalsToBrowser';
sub setup {
my $self = shift;
$self->start_mode( 'app_start' );
$self->run_modes( [ qw(
app_start
insert_project
) ] );
}
sub app_start {
my $self = shift;
my $template = $self->load_tmpl( 'in.html' );
# Set all template parameters to ''
my @parameter_names = $template->param();
my %params;
@params{ @parameter_names } = ('') x @parameter_names;
# Confirm certain values
$params{ HTML_Status } => 'foo';
# Add new values to template
$template->param( \%params );
return $template->output;
}
sub insert_project {
my $self = shift;
# Setup the template to use for the output.
my $q = $self->query();
my $template = $self->load_tmpl( 'in.html',
associate => $q,
die_on_bad_params => 0,
);
## Construct the SQL Statement and add results to template
# my $dbh = $self->param('mydbh');
# Output the template...
return $template->output;
}
1;
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
|
|
|
|
|