Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using multiple forms to submit to cgi

Status
Not open for further replies.

johnstacey

Programmer
Jan 31, 2004
2
Hi,
I am pretty new to CGI scripting. What I have is a submit process which runs over three pages. I need to be able to carry the info entered on page 1 to page 2 and then the info from the first 2 pages to page three. On page three the info entered by the user on the previous 2 pages is displayed for confirmation and then all sent to me using the submit button.
How can I carry info across from page to page and then display it on the last page before sending it to myself. Any help would be greatly appreciated,

Regards,

John
 
try using GET (<form name=&quot;form1&quot; method=&quot;get&quot; action=&quot;submit.pl&quot;>) - this information is then contained in the environment variable $ENV{'QUERY_STRING'}

this information is one long string appended to the URL like so- (this example takes any information after the question mark and 'illustrates' a number plate)

if you have an HTML page with 3 fields NAME, AGE and SEX for example - when submitted the URL might look like this:-

[red]?name=Duncan&age=34&sex=male[/red]

this information can be chopped up like this...

@pairs = split(/&/, $ENV{'QUERY_STRING'});

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$formdata{$name} = $value;
}


you can then use this information to build the next HTML page

Hope this is of use!


Kind Regards
Duncan
 
Hi Duncan,
that looks like what I am looking for. I will give it a go over the next few days and hopefully it will solve my problem. Thanks for your help,

Regards,

John
 
Here's how it should work.
1) The first form is displayed.
2) The form is filled out and submitted to your CGI.
3) The CGI gets the information from the form.
4) The CGI creates the second form with new fields. The fields from the first form are also put into this new form, but as hidden fields so the user doesn't see them.
5) The second form is filled out and submitted.
6) The CGI gets the information from the second form ( which as will have ALL the information that has been submitted so far).
7) The CGI displays this information for confirmation.


The first form doesn't need to be generated by CGI, it can be just plain html. The second and third pages can be either generated by separate cgi programs or by one cgi program. If you use one cgi program, you'll need it to check the fields it receives to see which page it should generate and display.

Also, look into using CGI.pm if you're not already. It simplifies a lot of the common cgi tasks, such as getting the fields from a submitted form and generating html.

Hope that helps!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top