CGI.pm textfield problem drove me crazy

W

wana

I was going crazy over this stupid thing because the second text field
wouldn't display $a. I had to put in -force=>1 for it to work. Is
that normal? I thought I had a bad CGI.pm, but Dr. Stein's examples
ran fine on my system. I scrutinized his simple examples so closely
and couldn't find what I was doing wrong. Of course, the examples I
was looking at didn't involve displaying a result in a textfield.

#!/usr/bin/perl
use CGI ':standard';
$a = "";
if (param)
{
@a = param('horse');
$a = join (',',@a);
$b = param('tuna');
$c = param('cow');
$a = "$a, $b, $c.";
}
print header;
print start_html({-bgcolor=>'pink',-title=>'poop'});
print start_form;

print
radio_group({-name=>'tuna',-value=>['rug','carpet','tile','wood'],-rows=>2}),
checkbox_group({-name=>'horse',-value=>['dog','cat','pig','turkey'],-rows=>2}),
textfield({-name=>'cow'}),
textfield({-name=>'chicken',-value=>$a,-force=>1}),
,submit({-name=>'enter'});

print end_form,end_html;
 
M

Mark Clements

wana said:
I was going crazy over this stupid thing because the second text field
wouldn't display $a. I had to put in -force=>1 for it to work. Is
that normal? I thought I had a bad CGI.pm, but Dr. Stein's examples
ran fine on my system. I scrutinized his simple examples so closely
and couldn't find what I was doing wrong. Of course, the examples I
was looking at didn't involve displaying a result in a textfield.

#!/usr/bin/perl
use CGI ':standard';
$a = "";
if (param)
{
@a = param('horse');
$a = join (',',@a);
$b = param('tuna');
$c = param('cow');
$a = "$a, $b, $c.";
}
<snip>
it may have something to do with what the passed parameters are (try
dumping Vars() somewhere), but...

1) your variable names aren't very helpful
2) you haven't reduced this problem to its smallest possible size before
posting
3) you haven't produced any output for us to scrutinize

so there isn't a lot for us to go on.

Mark
 
C

ctcgag

I was going crazy over this stupid thing because the second text field
wouldn't display $a.

I assume what you mean by that is that the 2nd time the cgi is invoked,
it returns "chicken" with the values that were submitted after the first
time the script was invoked, rather than the edited values you think it
should have. Right?

I had to put in -force=>1 for it to work. Is
that normal?

Yes. Without 'force' or some equivalent, when CGI regenerates the same
form that was just submitted, it uses the values that that parameter
currently has (i.e. It only uses your default value if there is no already
existing value in that parameter).

As an alternative to using force, you could just set the parameter to what
you want to be sometime before you print the form element:

param('chicken',$a);

Xho
 
W

wana

Yes. Without 'force' or some equivalent, when CGI regenerates the same
form that was just submitted, it uses the values that that parameter
currently has (i.e. It only uses your default value if there is no already
existing value in that parameter).

As an alternative to using force, you could just set the parameter to what
you want to be sometime before you print the form element:

param('chicken',$a);

Xho

Thanks! I like your way better than mine. Sorry about the oversized
example. I trimmed it:

#!/usr/bin/perl
use CGI ':standard';
$a = "";
if (param)
{
$a = param('cow');
}
print header;
print start_html, start_form,
textfield({-name=>'cow'}),
textfield({-name=>'chicken',-value=>$a,-force=>1}),
,submit({-name=>'enter'}), end_form,end_html;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,059
Members
48,769
Latest member
Clifft

Latest Threads

Top