Need Help With Hidden Fields
> Hi all,
> 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.
No you don't you just think you do.
> 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
Why? Are you interacting with a script you have no control over?
> 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
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.
> 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.
> 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
> 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...