CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
a script in several steps

 



jumaru
Deleted

Mar 1, 2000, 9:48 PM

Post #1 of 7 (981 views)
a script in several steps Can't Post

I would like to know how to make a script in several steps
Example for e-cards:
the user can choose an image and he has a button with "step2" and in the step2 he can choose the color of fonts.....
I hope you understand me
Thanks


perlkid
stranger

Mar 2, 2000, 2:10 AM

Post #2 of 7 (981 views)
Re: a script in several steps [In reply to] Can't Post

 
Iím working on a process similar to this. I am putting an extension on the urls like so;

<a href ="http://www.yoursite.com/cgi-bin/yourscripts.cgi?step=step2">

You could do this with links and with forms.

And in the perl you could do this, but I hope some one will tell you the easier way via a module, but I forgot what to do so I use this.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


sub parse_form {
my (@pairs, %in);
my ($buffer, $pair, $name, $value);

if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
else {
&cgierr('You cant run this script from telnet/shell.');
}

PAIR: foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

($value eq "---") and next PAIR;
exists $in{$name} ? ($in{$name} .= "~~$value") : ($in{$name} = $value);
}
return %in;
}
</pre><HR></BLOCKQUOTE>

put that at the bottom of your script and at the top put this

%in = &parse_form;

Then you could put step two in a sub called step two.


sub step_two {
print <<ENDHTML;
html
ENDHTML
}

you could have code or html, whatever you need. And towards the top of the program put

if ($in{'step'} eq "step2") { &step_two; }


and same with step 3 and so on.

This will execute step two if the urlís extension (step) is equal to step2.

I hope that will work for you but If any one knows how to read the url using that module I think Jumaru would be better off.

perlkid


darian
Deleted

Mar 2, 2000, 2:35 AM

Post #3 of 7 (981 views)
Re: a script in several steps [In reply to] Can't Post

perlkid your code is simply parsing the url information into variables. And easier way would be to use CGI.pm.

use CGI;
$q = new CGI;
$first_var = $q->param('first_var');
$second_var = $q->param('second_var');

This will save you from having to re-write what someone already has written.

As for your several steps simply add your variables passed from the previous form into your new form as hidden tags. Then when you are ready to process the information it will all be passed as one long string.

As for an if statement using CGI.pm to find out where to go you can use:

$step = $q->param('step');
&step2 if ($step == 2);

Hope this helps you out. BTW if you need more info on CGI.pm check out http://search.cpan.org/doc/LDS/CGI.pm-2.56/CGI.pm

Darian

[This message has been edited by darian (edited 03-02-2000).]


perlkid
stranger

Mar 2, 2000, 11:39 AM

Post #4 of 7 (981 views)
Re: a script in several steps [In reply to] Can't Post

 
I knew somone would know the easier route, Thanks for correcting me.

perlkid


jumaru
Deleted

Mar 2, 2000, 8:07 PM

Post #5 of 7 (981 views)
Re: a script in several steps [In reply to] Can't Post

Thanks a lot but I'm new in perl and I dind't understand Frown
I've tried this
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
$q = new CGI;
print $q->header();
$submit = $q->param('submit');

&step if($submit eq step);
&step2 if($submit eq step2);
&step3 if($submit eq step3);

sub step {
print "step\n";
}

sub step2 {
print "step2\n";
}

sub step3 {
print "step3\n";
}

</pre><HR></BLOCKQUOTE>
I have a blank page when I call the script
what's wrong ??
plese help


brian.hayes
User

Mar 2, 2000, 9:01 PM

Post #6 of 7 (981 views)
Re: a script in several steps [In reply to] Can't Post

You need to add "" around your vars in the if statments.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl
use CGI;
use CGI::Carp qw(fatalsToBrowser);
$q = new CGI;
print $q->header();
$submit = $q->param('submit');
&step if($submit eq "step");
&step2 if($submit eq "step2");
&step3 if($submit eq "step3");
sub step { print "step\n"; }
sub step2 { print "step2\n"; }
sub step3 { print "step3\n"; }

</pre><HR></BLOCKQUOTE>

also consider this

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl
use CGI;
use CGI::Carp qw(fatalsToBrowser);
$q = new CGI;
print $q->header();

## True or false "yourscript.pl?submit=step,2,3"
if($q->param('submit')){
if($q->param('submit') eq "step"){&step;}
if($q->param('submit') eq "step2"){&step2;}
if($q->param('submit') eq "step3"){&step3;}
} else { exit; }

sub step { print "step\n"; }
sub step2 { print "step2\n"; }
sub step3 { print "step3\n"; }

</pre><HR></BLOCKQUOTE>


jumaru
Deleted

Mar 2, 2000, 9:44 PM

Post #7 of 7 (981 views)
Re: a script in several steps [In reply to] Can't Post

Thanks brian
it works now

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives