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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi-Part Forms....

Status
Not open for further replies.

Vesku

Programmer
Jun 7, 2000
19
0
0
FI
Hello !<br><br>How can i make multi-part forms with one Perl-script ?<br><br>Exam.<br><br>Page 1<br>- Name<br>- Email<br>(When user click &quot;Next&quot; -button, name and email will return to Page 2)<br><br>Page 2<br>- Question 1<br>(When user click &quot;Next&quot; -button, all information will return to Page 3. If user's answer is right/wrong, then script calculate them, IE. right=3, wrong=1)<br><br>Page 3<br>- Question 3<br><br>...this loop will continue and last page send all information to me<br><br><br><br>Any ideas ??? PLEASE, HELP !!!<br><br>Thank You !!!<br><br><br>
 
Could you just add the names of the inputs and their values to a string which you send to each page as a hidden input? Then have a check for the last page and when you get to it send the whole hidden string (plus the last pages results) to whatever is going to process the data?<br><FONT FACE=monospace><br>read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});<br>$buffer =~ tr/+/ /;<br>$buffer =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;<br>@buffer_fields = split (/&/,$buffer);<br>foreach $field_in (@buffer_fields)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;($buffer_field_name,$buffer_field_value) = split (/=/,$field_in);<br>...<br></font><br><br>Then if you have called your hidden field &quot;data_so_far&quot; and the current pages input &quot;this_pages_data&quot; you can use those names again $buffer_field_value to know what bit of data you're looking at.<br><br>So if ($buffer_field__name eq &quot;data_so_far&quot;) then $buffer_field_value will contain the data collected in previous pages. Then append it to $buffer_field_value when ($buffer_field_name eq &quot;this_pages_data&quot;)....<br><br>Sorry I only know this long-winded way... Anyone that has a more efficient way - I'd be very keen to learn it too!<br><br>Rgds<br>Loon.
 
Hi Loon !<br><br>I have done like you said. Problem is, how can i make new HTML-page with one script and without writing information to file ? <br><br>Personal information<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Question 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Question 2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Question 3<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦<br>&nbsp;&nbsp;&nbsp;&nbsp;Last page<br><br><br>I should be like order-form or somekind Quiz...<br><br>Thanks!<br><br><br>
 
Hi Vesku,<br><br>&nbsp;&nbsp;&nbsp;I see your problem. The way I've done this in the past is that every page is using the same CGI script in it's forms method. <br><br>&nbsp;&nbsp;&nbsp;Then as part of you script I created the next page &quot;on the fly&quot; as it were with the same script. However, I don't think you need to do anything that complicated.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;You could try adding some JavaScript (am I allowed to say that in this forum??) to capture the user clicking the next button.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Another option might be to have a script per page, most of the script will be the same except each one can have a small section to load the next page in, write the http header (as below) and load in the page.<br><br><FONT FACE=monospace><br>#first write the http header (end with two newlines)<br>print &quot;Content-type:text/html \n\n&quot;;<br><br>#now we can either write the page a line at a time, or open a file and use that<br><br>open (INFILE, &quot;&lt;pageX.html&quot;) or die(&quot;Eeek, page X won't open!&quot;);<br>while (&lt;INFILE&gt;)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;print $_;<br>}<br>close (INFILE);<br></font><br>or do it the long way e.g.<br><FONT FACE=monospace><br>print &quot;&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;Page X - questions&lt;/title&gt;&lt;/head&gt;/n&quot;;<br>print &quot;&lt;body&gt;&lt;form name=question2&gt;&lt;input type=hidden name=valuessofar value=$myvalues&gt;&quot;;<br></font><br><br>and so on.<br><br>Maybe you could adapt the idea and make a single script that opens and prints out the correct page each time the user submits an answer. <br><br>Hope that helps,<br>bit long winded I know!<br><br>Cheers<br>Loon<br><br>
 
It may be a little tedious, but hidden HTML inputs will achieve the desired effect, I think.<br><br>With the dynamic creation of each page, include a hidden input of what page your on. <br><br><b>print &quot;&lt;input type=\&quot;hidden\&quot; name=\&quot;page\&quot; value=\&quot;$value\&quot;&gt;\n&quot;;</b><br><br>With the submission of the page, check the submitted step and progress to the next.<br><b>#!/usr/local/bin/perl -w<br># do the usual cgi parameter decoding......into %FORM.<br><br>$page = $FORM{page};<br>PAGE:<br>if ($page eq '1') <br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;#record page one stuff to disk or print to browser as hidden inputs( a little ugly)<br>&nbsp;&nbsp;&nbsp;&nbsp;&hdr;<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;Page two stuff to the browser including hidden input with page number&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;last PAGE;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>elsif ($page eq '2') <br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;#record page two stuff to disk or print to browser as hidden inputs( a little ugly)<br>&nbsp;&nbsp;&nbsp;&nbsp;&hdr;<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;Page three stuff to the browser&nbsp;&nbsp;including hidden input with page number&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;last PAGE;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>sub hdr <br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;Name - $FORM{$name}&lt;BR&gt;\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;Email - $FORM{$email}&lt;BR&gt;&lt;HR&gt;\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br></b><br><br><br>Won't this do what you are looking for??????<br>Hope this is helpful.<br><br>
 
Hi goBoating !<br><br>Thanks for your tips. They were very helpful. <br><br>Thanks to Loon too !!!<br><br><br><br><br>Vesku
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top