Re: Passing form data between scripts
by shemp (Deacon) on Apr 01, 2005 at 00:26 UTC
|
hidden form fields is one way. | [reply] |
|
Hi,
How do I accomplish using hidden form fields?
Do I define the hidden fields in the first form which passes to the first script (camp.cgi)?
Thanks for your help.
| [reply] |
|
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] |
|
|
Re: Passing form data between scripts
by Joost (Canon) on Apr 01, 2005 at 00:49 UTC
|
First of all, why split the whole thing up in seperate programs?
Just use a session to store the data and process it later. For a better way of building your application take a look at CGI::Application.
| [reply] |
|
Hi,
Using the session link you gave me, I read about the CGI::Session.
Can you tell me what I'm supposed to do with this line of code:
my $session = new CGI::Session("driver:File", undef, {Directory=>'/tmp
+'});
I'm not sure what I'm supposed to do with it or how it's supposed to be used. Can you explain?
Thank you. | [reply] [d/l] |
|
| [reply] |
|
Re: Passing form data between scripts
by Popcorn Dave (Abbot) on Apr 01, 2005 at 04:54 UTC
|
Something else you may want to consider is to make your script re-entrant using CGI.pm. It's similar to what Joost said.
I'm doing that with a simple shopping cart application now. Since I didn't specify an action in my form, the application calls itself again when the submit button is pressed. I'm using this method to both check to make sure I have data in required fields, and to untaint it as well. The CGI docs have some good examples of this.
HTH!
Useless trivia: In the 2004 Las Vegas phone book there are approximately 28 pages of ads for massage, but almost 200 for lawyers.
| [reply] |
Re: Passing form data between scripts
by TedPride (Priest) on Apr 01, 2005 at 07:56 UTC
|
I'd use the same script for the whole process. Just include a flag at each step so you know which part to run:
if (!$part) {
# Print part 1, which includes:
<input type="hidden" name="part" value="1">
}
elsif ($part == 1) {
# Process part 1
# Print part 2, which includes:
<input type="hidden" name="part" value="2">
}
elsif ($part == 2) {
# Rinse and repeat as many times as necessary...
}
I wouldn't mess with sessions or database storage for something as simple as this. | [reply] [d/l] |