|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
it should be able to add the if condition to validate the user inputs when developing cgi using html::template module, bye why my cgi script that uses html::template only responses the last if statement instead of checking from the 1st if statement so on. for example, this is a piece of code from my script,
#!/usr/bin/perl use HTML::Template; print "Content-type:text/html\n\n"; my $template = HTML::Template->new(filename => 'test.tmpl'); .. if (!$tempale->param(username => '') or !$template->param(password => '')){ print "Invalid registration"; } if (!$template->param(username => ''){ print "Invalid username"; } print $template->output; The problem is why It always returns the second if statement even I already put words in the username field. I was trying to put a piece of information on the sign-in form and call the static html, rather than re-print all the static layout. Is it the correct way to do? |
|
#2
|
|||
|
|||
|
I'm not sure if this is the right answer, but don't you have to pass the CGI.pm query to HTML::Template inorder to be able to access form infomation using:
$template->param(username => ''); Why not try using $q = new CGI; if(!$q->param(username)) { print "invalid username" } hope that helps |
|
#3
|
|||
|
|||
|
thanks for your reply unobserved.
actually if you put <TMPL_VAR NAME = 'param'> together with INPUT TAG like this: <INPUT NAME=param TYPE=TEXT VALUE="<TMPL_VAR NAME="username">"> then you will be able to manipulate the parameter in your CGI script, if (!$template->param(username => ''){ .... } my CGI can return the parameter to HTML using this method, but the problem is when I add another IF statement, the logic always goes to the last IF statement without analyzing the previous ones. It's weird :-) |
|
#4
|
|||
|
|||
|
in that case .. it .. correct me i'f i'm wrong, but
if(!$template->param(username => '') <-- does that statement not mean : if not user name has a value, basically do this if username has any value. what about Code:
if($template->param(username => '') || $template->param(password => '')) {print 'invalid registration'; }
elsif($template->param(username => '')) { print "unknown user"; }
notice no !'s. just my suggestion |
|
#5
|
|||
|
|||
|
hi observed,
I know I shouldn't put the '!' in front of $template. I had tried to take out the '!', but nothing came out. By adding '!' at least I got something, but unfortunately is still not that I want. Anyway, thanks for your suggestion. There's something to share with you, according to Sam Tregar HTML:Template can't do input processing, it only handles ouput. Regards, |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > if statement using HTML::TEMPLATE |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|