In one page, inside a form, you can have a hidden field of the form
<input type="hidden" name="thing" value="$thing">
and the script invoked by the form then gets the value by
using param (using CGI.pm, of course), i.e.
$thing=param('thing')
You can use CGI.pm to produce the code for the hidden field
using something like
print hidden(-name=>"thing1",-value=>"thing2");
but I seem to recall having difficulty getting variables
to interpolate in the value, so I've usually used the explicit first way. (If someone can comment on the interpolation problem, I'd be happy to hear about that...)
The CGI module has built-in handling of "stickiness" (i.e.
maintaining state (and I believe this makes use of hidden fields in a clever way... I don't understand it very well)) but it usually takes me such a lot of
messing around to get it to work properly that I mostly
just use hidden fields myself. That's not meant to detract
from CGI.pm at all - it is a wonderful tool, I just don't
know it well enough. (I always use CGI.pm, I just don't
always use all of the subtleties available.)
chas
| [reply] [d/l] [select] |
Hi,
Thanks for the reply. I think I see where you're going with this. I just want to clarify something.
The form that is being sumbitted is an HTML form. One of the fields is name. From articles I read about HTML and hidden fields, when I type the following line:
<input type="hidden" name="member" value="hard coded value">
The "value" parameter in the articles are setting a hard coded value to each name="member". In this case, the value for name or member is going to be different for every person who completes the form.
How do I write my hidden field in the form so it doesn't pass hard coded values instead it will pass the actual info entered by the person completing the form? I guess what I'm asking is how do I set a value for "member" that is global? I think?.
Thanks.
| [reply] [d/l] |
If you just want to pass values entered by a user, you could
have something like
<input type="text" name="N" size="35">
and then in the action
script use $name=param('N')
to collect it. I use hidden fields in a case where I may
not be using $name imediately, but I want the script to print out new HTML for a page with a new form and I want $name to be available in that form. In that case I would store $name as the value in a hidden field and then when the
new form is submitted the script can collect the value.
(For
example I wrote a webmail client where at some point I use a script to print
an HTML page with an email printed on the page. I store the message text and sender's email address in a form in hidden fields so
I can click on a reply button and open up a reply window where the address appears in a textbox and the quoted email
appears in a textarea. Then I can enter my reply in that same textarea and send off the reply with another script.
The address and original email text are parsed and
saved on the read page so they could be used on the reply page. Of course, there are various ways to do this sort of
thing. You can save things by having them appear as values
in various input widgets like textboxes, but sometimes you may not want them visible immediately.)
chas
(Update: Maybe I was unsure what you meant and was too long winded...should have just said that instead of
using a string for the value, use for the value a variable
which contains some info you have collected from the user.
That's what I indicated in my first reply
<input type="hidden" name="thing" value="$thing">
) | [reply] [d/l] [select] |