Need Help With Hidden Fields 
Author Message
 Need Help With Hidden Fields

Hi all,

I'm quite new to Perl, so please be patient.I'm going out of my mind
with this...

I'm using CGI.pm in a form.

use CGI;
my $cgi = new CGI;

I create two submit buttons and need to pass a hidden field to
determine which of the two buttons was pressed.

Now, you're thinking, you can just do $cgi->param('button_name'), but
each button needs to be tagged as 1 or 2...and *that's* what I need to
know.

My code looks like:

 print $cgi->submit (-name=>'job', -value=>'Close'),
       $cgi->hidden (-name=>'msg', -value=>'1'),
       $cgi->submit (-name=>'job', -value=>'Open'),
       $cgi->hidden (-name=>'msg', -value=>'2');

When I do this, two things happen:

1) It prints out these tags in the HTML source *way too many*
times...cuts off the text to really tell how many.

2) There is no link created between the submit button and the
associated hidden value.

When I output the value for $cgi->param('msg') in the browser, it
always prints out 1, no matter which button I press.

Can someone help me please!?? I *really* have to know this soon. Thanks
a lot!

- MinNY

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Mon, 24 Jun 2002 03:00:00 GMT  
 Need Help With Hidden Fields

Quote:

> Hi all,

Hi,

Quote:
> I'm using CGI.pm in a form.

> use CGI;
> my $cgi = new CGI;

Good start.

Quote:
> I create two submit buttons and need to pass a hidden field to
> determine which of the two buttons was pressed.

No you don't you just think you do.

Quote:
> Now, you're thinking, you can just do $cgi->param('button_name'), but
> each button needs to be tagged as 1 or 2...and *that's* what I need to
> know.

Why? Are you interacting with a script you have no control over?

Quote:
> My code looks like:

>  print $cgi->submit (-name=>'job', -value=>'Close'),
>        $cgi->hidden (-name=>'msg', -value=>'1'),
>        $cgi->submit (-name=>'job', -value=>'Open'),
>        $cgi->hidden (-name=>'msg', -value=>'2');

This is nothing to do with Perl it's a basic CGI thing. I suggest you go
read up on how CGI works as I think you missed a fairly important aspect
of it.

Anyway to do what you want you will need each submit button and hidden
field pair in a seperate form.

However a better way would be to change the script receiving the input so
it can react to the names of the submit buttons, again if you can.

Quote:

> When I do this, two things happen:

> 1) It prints out these tags in the HTML source *way too many*
> times...cuts off the text to really tell how many.

You have other problems. I doubt this is related to you query above.

Quote:
> 2) There is no link created between the submit button and the
> associated hidden value.

As I said you missed something vital when trying to understand CGI, any
decent book on the sibject will explain the flaw in what you are trying to
do.

Quote:

> When I output the value for $cgi->param('msg') in the browser, it
> always prints out 1, no matter which button I press.

Correct that's what it should do.

--
Ian J. Garlick                                     Quote No. 25

It's not reality or how you perceive things that's important -- it's
what you're taking for it...



Tue, 25 Jun 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Need Help With Hidden Fields

2. God help me!Hidden fields.

3. Need Help submitting hidden values to .cfm via PERL

4. Hidden Fields: weird behavior? (CGI.pm)

5. CGI.pm creates hidden field '.cgifields'

6. Hidden fields and email spiders

7. Problem with CGI.pm and Hidden Fields

8. WWW::Mechanize & hidden field changed by javascript

9. Hidden field???

10. hidden field displays old value

11. add value of hidden field in the search query

 

 
Powered by phpBB® Forum Software