
|
Hidden fields are best generated by the same CGI script that processes
the initial form - that is, the one that contains the data to be stored.
Then you'll create a second script to process the final form - the one
that contains both the new data and the stored data.
The bottom line is - the script that processes the data to be stored should generate the hidden fields in the next form. Hidden fields are useful but transitory. Once your visitor leaves your site or even jumps to a page that's outside the realm of the interconnected scripts that store and generate the hidden fields, the connection between the visitor and the information you're currently collecting is lost. Parse the Form using the same procedure as those used in Week 6 Perl CGI's section. ********** hidden1.pl ********** #!/usr/local/bin/perl read(STDIN, $input, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $input); foreach $pair (@pairs) { print "Content-type:text/html\n\n"; print "<HTML>\n"; print "<BODY bgColor=\"white\">\n\n"; print "Thank you, $formdata{'name'}, for entering your personal data.<BR>\n"; print "Now you can choose which items you'd like to purchase.<P>\n"; print "<FORM METHOD=\"POST\"
ACTION=\"hidden2.pl\">\n"; # %formdata is the name of the Associative Array the contains the foreach $key (keys %formdata) { } print "<INPUT TYPE=\"submit\" VALUE=\"Send
order\">\n"; print "</BODY>\n"; ********** End of hidden1.pl ********** ********** hidden2.pl ********** #!/usr/local/bin/perl read(STDIN, $input, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $input); foreach $pair (@pairs) { print "Content-type:text/html\n\n"; print "<HTML>\n"; print "<BODY bgColor=\"white\">\n"; print "The item ordered by $formdata{'name'} from $formdata{'state'} is\n"; print "<P>$formdata{'item'}\n"; print "<P>Thank you for your order. It's on its way.\n\n"; print "</BODY>\n"; ********** End of hidden2.pl ********** |