in reply to Multiple form survey
1.) The script proceeds to the 2nd form without me completeing the 1st. Problem 2.) The 2nd form is upended at the bottom of the 1st, not in its own window.
Sounds to me like you're operating under the assumption that your script will run once. CGI doesn't work that way. Your script will run each time the user loads the page, whether they do it by hitting reload, by clicking submit, or whatever. Each time it runs, it should only print the one page that is wanted under the circumstances. For example, if the user hasn't submitted any form yet, you want to print the blank first form. If they are just now sumbitting the first form, you want to print the second one (assuming that their answers to the first are okay). If they're submitting the second form, you want to print some kind of confirmation. So you want to do something along these lines...
%input = getforminput(); # That's another thread... if ($input{formsubmitted}==2) { # user submitted form2. Process it and print a # "form sumbitted" advisory page. } elsif ($input{formsubmitted==1) { # user submitted form1. Process it and print form2. } else { # User didn't submit anything yet. Print form1. }
This is just a basic structure. You may alter it an any number of ways. For example, you may wish to validate the forms the user has submitted and make the user correct any mistakes, only giving them the next form (or results) if they've given satisfactory answers to all required fields. Also note that the formsubmitted input is not magic; your form has to supply it. One way to do it is to put hidden fields in your forms, for example:
<input type="hidden" name="formsubmitted" value="2"></input>
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/
|
|---|