value of param

S

sam

Hi,

I have a problem with using CGI module in perl to keep track which
submit button was pressed.

use CGI;
use CGI::Carp qw/fatalsToBrowser/;
$query = new CGI;

if (!$query->param) {
print $query->startform(-target=>'_new');
print "<table border width=100% >\n";
......

print $query->submit(but1);
}
elsif ($query->param(but1)) {
print "param: $query->param(but1),"<br>\n";
}

When I press the submit button "but1", the "elsif" clause does not execute.

Thanks
Sam
 
A

Arndt Jonasson

sam said:
I have a problem with using CGI module in perl to keep track which
submit button was pressed.

use CGI;
use CGI::Carp qw/fatalsToBrowser/;
$query = new CGI;

if (!$query->param) {
print $query->startform(-target=>'_new');
print "<table border width=100% >\n";
.....

print $query->submit(but1);
}
elsif ($query->param(but1)) {
print "param: $query->param(but1),"<br>\n";
}

When I press the submit button "but1", the "elsif" clause does not execute.

There is something wrong on the last 'print' line: it has three
double quote characters.
 
P

Paul Lalli

sam said:
Hi,

I have a problem with using CGI module in perl to keep track which
submit button was pressed.

use CGI;
use CGI::Carp qw/fatalsToBrowser/;
$query = new CGI;

you forgot to print $query->header();

you forgot to print the starting html
if (!$query->param) {
print $query->startform(-target=>'_new');
print "<table border width=100% >\n";
.....

print $query->submit(but1);

you forgot to print the end of the form
}
elsif ($query->param(but1)) {
print "param: $query->param(but1),"<br>\n";

malformed print statement.

you forgot to print the ending html
When I press the submit button "but1", the "elsif" clause does not
execute.

No one can help you if you don't post your actual code. Copy and paste
what you're actually using, don't retype it. Have you seen the posting
guidelines that are posted here twice a week?

An example of your code with the two major errors corrected works
perfectly for me:
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
my $query = new CGI;

print $query->header();

if (!$query->param) {
print $query->startform(-target=>'_new');
# print "<table border width=100% >\n";
#.....

print $query->submit(but1);
}
elsif ($query->param(but1)) {
print "param: ", $query->param(but1),"<br>\n";
}

__END__


Please post your actual code, and perhaps someone can help.

Paul Lalli
 
S

sam

Paul said:
you forgot to print $query->header();

you forgot to print the starting html




you forgot to print the end of the form




malformed print statement.




you forgot to print the ending html



execute.

No one can help you if you don't post your actual code. Copy and paste
what you're actually using, don't retype it. Have you seen the posting
guidelines that are posted here twice a week?

An example of your code with the two major errors corrected works
perfectly for me:
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
my $query = new CGI;

print $query->header();

if (!$query->param) {
print $query->startform(-target=>'_new');
# print "<table border width=100% >\n";
#.....

print $query->submit(but1);
}
elsif ($query->param(but1)) {
print "param: ", $query->param(but1),"<br>\n";
}

__END__
Thanks, it works.
Since I m writing a module for webmin. If I include this module in the
webmin "enviornment", I will need to include webmin's libaries files
which actually makes the value of "but1" goes to somewhere, probably
consumed by the webmin header files.
The file and function I used in this webmin module are:
do '../web-lib.pl';
&init_config();
&ReadParse();

I m thinking how to keep the webmin headings appear while preserved the
CGI functionality of my module.

Thanks
Sam
 
S

sam

sam said:
Paul Lalli wrote:

Thanks, it works.
Since I m writing a module for webmin. If I include this module in the
webmin "enviornment", I will need to include webmin's libaries files
which actually makes the value of "but1" goes to somewhere, probably
consumed by the webmin header files.
The file and function I used in this webmin module are:
do '../web-lib.pl';
&init_config();
&ReadParse();

I m thinking how to keep the webmin headings appear while preserved the
CGI functionality of my module.
I just managed to fix the problem by removing the init_config() function
call in the lib.pl file in my module.

Sam.
 
S

sam

Paul said:
An example of your code with the two major errors corrected works
perfectly for me:
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
my $query = new CGI;

print $query->header();

if (!$query->param) {
print $query->startform(-target=>'_new');
# print "<table border width=100% >\n";
#.....

print $query->submit(but1);
}
elsif ($query->param(but1)) {
print "param: ", $query->param(but1),"<br>\n";
}
Hi, if I have another text field with the value of "bob" as shown below:
$query->textfield({name=>'Name', value=>"bob"});

how can I pass its value to another cgi when the button is pressed?

I have written a if..{} statement as shown below:
if ($query->param('Name')) {
# goes to form2.cgi with Name and its value "bob"
}

Thanks
Sam
 
M

Matt Garrish

sam said:
Hi, if I have another text field with the value of "bob" as shown below:
$query->textfield({name=>'Name', value=>"bob"});

how can I pass its value to another cgi when the button is pressed?

use LWP::Simple;

Read lwpcook.

You really need to take a few steps back and learn a bit more about the
technologies you're using. Your questions about how to do things in html are
going to get you killfiled (if they haven't already), as they don't belong
in this group. And your race to accomplish whatever it is your doing will
inevitably result in an unmaintainable mess if you try to keep hacking in
solutions. It's better to do something right once than spend months cleaning
up your own mistakes.

Matt
 
I

ioneabu

Here is a little tested sample which uses multiple forms within one
page. There are some problems with doing it this way. From CGI home
page:

General note 3. You can put multiple forms on the same page if you
wish. However, be warned that it isn't always easy to preserve state
information for more than one form at a time. See advanced techniques
for some hints.

http://stein.cshl.org/WWW/software/CGI/#advanced

#!/usr/bin/perl

use CGI q:)standard);
use warnings;
use strict;

print header();
print start_html();
print start_form(-action=>'form1.cgi');
print textfield({name=>'Name', value=>"bob"});
print br();
print submit(-name=>'goto form1.cgi');
print end_form();
print start_form(-action=>'form2.cgi');
print submit(-name=>'goto form2.cgi');
print end_form();
print start_form(-action=>'form3.cgi');
print submit(-name=>'goto form3.cgi');
print end_form();
print end_html();


Good Luck!

wana
 
S

sam

Here is a little tested sample which uses multiple forms within one
page. There are some problems with doing it this way. From CGI home
page:

General note 3. You can put multiple forms on the same page if you
wish. However, be warned that it isn't always easy to preserve state
information for more than one form at a time. See advanced techniques
for some hints.

http://stein.cshl.org/WWW/software/CGI/#advanced

#!/usr/bin/perl

use CGI q:)standard);
use warnings;
use strict;

print header();
print start_html();
print start_form(-action=>'form1.cgi');
print textfield({name=>'Name', value=>"bob"});
print br();
print end_html();
Do you know how to pass the variable name "Name" and its value "bob" to
form1.cgi?

Thanks
Sam
 
J

John Bokma

sam said:
Do you know how to pass the variable name "Name" and its value "bob"
to form1.cgi?

That already happens (unless someone changes the value ;-) ).

Also, note that the print part above can be simplified as follows:

print header(),
start_html(),
:
end_html();

(ie, just one print). And I guess you can drop the () too :-D.
 
S

sam

John said:
sam wrote:




That already happens (unless someone changes the value ;-) ).

Also, note that the print part above can be simplified as follows:

print header(),
start_html(),
:
end_html();

(ie, just one print). And I guess you can drop the () too :-D.

OK, this is perfectly fine.
But whatif I put another paire of "embedded" start_form and end_form
within one start_form and end_form, something like the following coding:

print $query->start_form(-action=>'Main.cgi');
print $query->textfield({name=>'Name', value=>"bob"});
print $query->br();

print $query->start_form(-action=>'form5.cgi');
print $query->submit(-name=>'goto form5.cgi');
print $query->end_form();

print $query->submit(-name=>'goto Main.cgi');
print $query->end_form();

When press the form5 button, it will certainly go to Main.cgi instead of
form5.cgi.
Is there a way fix this error?
I was thinking use javascript to construct the part of "action
form5.cgi" and its submit button (form5). What do you think this idea?

I have a looked at LWP before, but there is no instruction/example about
how to deal with this situiation.

Thanks
Sam
 
S

sam

sam said:
OK, this is perfectly fine.
But whatif I put another paire of "embedded" start_form and end_form
within one start_form and end_form, something like the following coding:

print $query->start_form(-action=>'Main.cgi');
print $query->textfield({name=>'Name', value=>"bob"});
print $query->br();

print $query->start_form(-action=>'form5.cgi');
print $query->submit(-name=>'goto form5.cgi');
print $query->end_form();

print $query->submit(-name=>'goto Main.cgi');
print $query->end_form();

When press the form5 button, it will certainly go to Main.cgi instead of
form5.cgi.
Is there a way fix this error?
I was thinking use javascript to construct the part of "action
form5.cgi" and its submit button (form5). What do you think this idea?

I have a looked at LWP before, but there is no instruction/example about
how to deal with this situiation.
I think use html frame would do that trick? One frame contains a form of
Main.cgi-Main button, another frame contains a form of form5.cgi-form5
button.

Sam.
 
S

Sherm Pendley

sam said:
But whatif I put another paire of "embedded" start_form and end_form
within one start_form and end_form, something like the following coding:

I've answered this before - why aren't you listening?

Nested forms are not allowed in HTML. It doesn't matter how the HTML is
produced, by Perl, Java, or a text editor - it's invalid HTML.

sherm--
 
S

Sherm Pendley

sam said:
I think use html frame would do that trick?

Don't be silly - you're grasping at straws.

You need to take a huge step back and rethink your basic design. Go to a
CGI group - comp.infosystems.www.authoring.cgi, for instance - and ask
about *what* you want to do, not *how* you think you want to do it.

sherm--
 

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

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,440
Latest member
YoungBorel

Latest Threads

Top