Click to See Complete Forum and Search --> : Having problem with hidden field


udsrem
12-01-2002, 10:38 PM
I was wondering if someone could help me with this program.
This program should work, but for some reason the hidden field dose not change when the programs runs. The program is listed below.

#!/usr/bin/perl

use CGI qw(-nosticky :all );
use CGI::Carp 'fatalsToBrowser';
$query = new CGI;
print $query->header;
print $query->start_html(-title=>'Blank Page',-style=>{'rel'=>'stylesheet','type'=>'text/css', 'src'=>'somekind.css'}, -class=>'content');

if ($query->param('help me') ) {
print $query->start_form({-method=>'post' ,-action=>'blank.cgi' ,-name=>'blank_form'});

print $query->hidden({-name=>'help me' ,-value=>'fdjlkjgsreughfjvkbsur/asadfdaseg'}); #hidden field when button pressed 1st time

print $query->start_table({-width=>'100%'});
print $query->Tr(td({-valign=>'bottom', -width=>'30%'},div({-class=>'page-title1'},Some kind of header!')),
td({-width=>'80%' ,-class=>'context'}),'Sorry, no help on this page',td({-align=>'right' ,-width=>'20%' },
image_button({-name=>'Help me' ,-src=>'/images/context_help.gif' ,-align=>'absmiddle' ,-height=>'17' ,-alt=>'Help' ,-border=>'0' ,class=>'button-context' ,-width=>'17'}))),
Tr(td({-class=>'table-line' ,-height=>'1' ,-colspan=>'7'}));
}
else {
print $query->start_form({-method=>'post' ,-action=>'blank.cgi' ,-name=>'blank_form'});

print $query->hidden({-name=>'help me' ,-value=>'fdjlkjgsreughfjvkbsurdtur'}); # hidden field on first run and when button pressed 2nd time

print $query->start_table({-width=>'100%'});
print $query->Tr(td({-valign=>'bottom', -width=>'30%'},div({-class=>'page-title1'},Some kind of header!')),
td({-width=>'80%' }),td({-align=>'right' ,-width=>'20%' },
image_button({-name=>'Help me' ,-src=>'/images/context_help.gif' ,-align=>'absmiddle' ,-height=>'17' ,-alt=>'Help' ,-border=>'0' ,class=>'button-context' ,-width=>'17'}))),
Tr(td({-class=>'table-line' ,-height=>'1' ,-colspan=>'7'}));
}
print $query->end_table;
print $query->end_form;
print end_html;

When the program runs it falls to the else statement and the form runs. When you click the image button the form changes and tells the user that there is no help on this page.

That works correctly, the problem is when you click the button again it should change back. It is not changing the hidden field it seems as if the hidden field is over looked. If I change the hidden fields name when the condition is true it works correctly. ('help me' to 'Help me')

I need to make it work with the hidden fields name staying the same at all times, just the value changes.

Can this be done and how.

Thanks

jeffmott
12-02-2002, 03:24 AM
I'm surprised it compiled at all. Twice you have the text string 'Some kind of header!' with a closing quote but no opening.

The "Sorry, no help on this page" does no go away because you have the hidden element in both the true _and_ false sections of the if statement. The hidden value should be omitted if 'help me' has a value, so that the next time the form is submitted 'help me' will not have a value.

As far as changing the case on 'help me' and 'Help me', you can see in the resulting page that the name is still in all lowercase. If you present 'HELP ME' in all uppercase, the resulting page still presents it in all lowercase. This is perhaps a bug in CGI.pm. I personally find it more convienent to generate my HTML content with print statements rather than the CGI module. But this is only a preference and is up to you.

udsrem
12-02-2002, 10:00 AM
Thanks Jeff, that was mis-typing on my part there is an open quote in the program. Sorry for that. I'll keep trying thanks again.