Welcome to WebmasterWorld Guest from 54.242.105.196

Forum Moderators: coopster & jatar k & phranque

Passing set of values across multiple forms

I used freeze and thaw

   
3:23 pm on Jan 19, 2009 (gmt 0)

5+ Year Member



I'm having multiple forms in a single CGI file, and loaded one form at a time based on the button selected. I will call the functions from the main code. I have multiple fields in each form, need to pass across all the forms. I'm creating HASH for the fields and values in each form as it goes. I use "thaw" and "freeze" for converting the HASH into a single string and send it in the hidden field to the next form, and then in the next form I'm getting the String into a hash through "thaw".

The problem I'm facing is I'm not able to access the passing value in the next form, since I'm initializing the value for the HASH variable at the starting, and because of that I'm always having null value at that form.

Can some one help me to solve this issue.

Thanks,
Jagan

6:22 pm on Jan 19, 2009 (gmt 0)

5+ Year Member



The some what standard way of doing what you are wanting to do is using CGI::Session, which handles all the backend requirements to make the form data persistent across invocations of a CGI script. Some servers have it installed and some don't. There is also CGI::Persistent which I have never used and appears to be a fairly new module. Or you can write your own routines to handle the data that needs to be carried over from form to form.

I assume you are using Storable to freeze/thaw the data. I believe that will work but I have never tried it for a CGI script. As long as you are using a disk file to store the data it sounds like it should work. The problem might be in how you are using it, which nobody here can see.

4:58 am on Jan 20, 2009 (gmt 0)

5+ Year Member



Thanks Krugs.

The problem is I don't want to use Cookie or Session ID based handling to get the data from the file. I'm looking for simple solution. I will look into CGI::Persistent as you said.

8:25 am on Jan 21, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



are you dealing with big amounts of data to be transfered?
Usually, I'd recommend the simple approach to just add a couple of hidden fields to your form and just push in all the parameters you'd like to pass through to the next call of your cgi-script. that way, you'll just have to read the parameters with CGI.pm (or whatever you're using to get them) and "it just works".
9:37 am on Jan 21, 2009 (gmt 0)

5+ Year Member



Hi all,

Thanks for the replies, it just the programming error I did which lead to the above problem.

Basically what I tried to do is...

1. keep dummy value in Hash as intial value as "Dummy", 0.
2. Convert the Hash into string using "Thaw"
3. Pass it on to next form in the hidden field
4. Get the string from hidden field
5. Convert the string back to Hash using "Freeze"
6. Get the values given by the user in the previous form and update the value in the Hash (Now Hash contains both the initial value as well as the previous form activated values)
7. Repeat steps 2 to 6 in all the forms where you want the values of previous form variables

When I programmed I left the 4th step which lead to current values always in the Hash.

After 1 full day frustation I found the basic problem in the next days with in 10mts..

Break is better always.. it seems.

Anyway thanks for all the help. With this problem only I found "Only string can be passed through hidden field not Hash" while googling. Also found there is possibility to pass the Hash as Hidden field by converting Hash into string and vice versa using the "Freeze-Thaw" module available in the CPAN.

Thanks once again.
Jagan

6:31 pm on Jan 21, 2009 (gmt 0)

5+ Year Member



Well done. Taking a break can be a big help. Fresh eyes and a clear mind can be invaluable in solving a problem.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month