Click to See Complete Forum and Search --> : perl & CGI (param())


saturn-vk
03-14-2004, 07:14 AM
Why is it that when I have a perl script with already activated params, (say, a multipage perl script, different pages activated with different params), and I try to do something with forms (like create a directory or upload an image or whatever), and i try to call the results like this

if (param("name")) {
stuff
} else {
regular stuff
}

it just executes the starting page (the one that starts if there aren't any params). In the man pages and various tutorials, they just use if (param()), but that's because they don't have any other activated params, but I do.

How do I remedy this problem?

scinerd
03-14-2004, 09:40 AM
so your code looks to be ok so it's got to be a problem with something your not showing. I'm new to cgi so I wrote this little scrip and it work that way you want.


#!/usr/bin/perl
use CGI ':standard';

print header, start_html('test');

$value = param('name');
print "name value:$value<p>";

if (param("name")) {
print "got it";
} else {
print "stuff";
print start_form,
checkbox(-name=>'name',-checked=>0),
submit(-name=>'Set'),
end_form,
}

print end_html;

for testing I would put the two lines at the start where I print param('name') this is nice since you can see what ti's set to if anything. My guess is it's not being set. In my code it prints nothing after "name value;" till you check the box and hit submit

saturn-vk
03-14-2004, 10:47 AM
try adding everything after "print header, start_html('test');" in an if -else statement like so and see what I mean:

if (param("other")) {
$other = param("other");
print $other;
} else {
print start_form,
textfield(-name=>"other"), submit,
end_form;


$value = param('name');
print "name value:$value<p>";

if (param("name")) {
print "got it";
} else {
print "stuff";
print start_form,
checkbox(-name=>'name',-checked=>0),
submit(-name=>'Set'),
end_form,
}
}


check if "print "got it";" will display at all, or will it return you to this instead
print start_form,
textfield(-name=>"other"), submit,
end_form;