×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Multi-Part Forms....

Multi-Part Forms....

Multi-Part Forms....

(OP)
Hello !

How can i make multi-part forms with one Perl-script ?

Exam.

Page 1
- Name
- Email
(When user click "Next" -button, name and email will return to Page 2)

Page 2
- Question 1
(When user click "Next" -button, all information will return to Page 3. If user's answer is right/wrong, then script calculate them, IE. right=3, wrong=1)

Page 3
- Question 3

...this loop will continue and last page send all information to me



Any ideas ??? PLEASE, HELP !!!

Thank You !!!


RE: Multi-Part Forms....

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?

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
$buffer =~ tr/+/ /;
$buffer =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
@buffer_fields = split (/&/,$buffer);
foreach $field_in (@buffer_fields)
{
    ($buffer_field_name,$buffer_field_value) = split (/=/,$field_in);
...


Then if you have called your hidden field "data_so_far" and the current pages input "this_pages_data" you can use those names again $buffer_field_value to know what bit of data you're looking at.

So if ($buffer_field__name eq "data_so_far") then $buffer_field_value will contain the data collected in previous pages. Then append it to $buffer_field_value when ($buffer_field_name eq "this_pages_data")....

Sorry I only know this long-winded way... Anyone that has a more efficient way - I'd be very keen to learn it too!

Rgds
Loon.

RE: Multi-Part Forms....

(OP)
Hi Loon !

I have done like you said. Problem is, how can i make new HTML-page with one script and without writing information to file ?

Personal information
         ¦
     Question 1
         ¦
     Question 2
         ¦
     Question 3
         ¦
         :
         ¦
    Last page


I should be like order-form or somekind Quiz...

Thanks!


RE: Multi-Part Forms....

Hi Vesku,

   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.

   Then as part of you script I created the next page "on the fly" as it were with the same script. However, I don't think you need to do anything that complicated.

    You could try adding some JavaScript (am I allowed to say that in this forum??) to capture the user clicking the next button.

    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.


#first write the http header (end with two newlines)
print "Content-type:text/html \n\n";

#now we can either write the page a line at a time, or open a file and use that

open (INFILE, "<pageX.html") or die("Eeek, page X won't open!");
while (<INFILE>)
{
    print $_;
}
close (INFILE);

or do it the long way e.g.

print "<html>\n<head>\n<title>Page X - questions</title></head>/n";
print "<body><form name=question2><input type=hidden name=valuessofar value=$myvalues>";


and so on.

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.

Hope that helps,
bit long winded I know!

Cheers
Loon

RE: Multi-Part Forms....

It may be a little tedious, but hidden HTML inputs will achieve the desired effect, I think.

With the dynamic creation of each page, include a hidden input of what page your on.

print "<input type=\"hidden\" name=\"page\" value=\"$value\">\n";

With the submission of the page, check the submitted step and progress to the next.
#!/usr/local/bin/perl -w
# do the usual cgi parameter decoding......into %FORM.

$page = $FORM{page};
PAGE:
if ($page eq '1')
    {
    #record page one stuff to disk or print to browser as hidden inputs( a little ugly)
    &hdr;
    print "Page two stuff to the browser including hidden input with page number";
    last PAGE;
    }
elsif ($page eq '2')
    {
    #record page two stuff to disk or print to browser as hidden inputs( a little ugly)
    &hdr;
    print "Page three stuff to the browser  including hidden input with page number";
    last PAGE;
    }

sub hdr
    {
    print "Name - $FORM{$name}<BR>\n";
    print "Email - $FORM{$email}<BR><HR>\n";
    }



Won't this do what you are looking for??????
Hope this is helpful.

RE: Multi-Part Forms....

(OP)
Hi goBoating !

Thanks for your tips. They were very helpful.

Thanks to Loon too !!!




Vesku

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close