Gossamer Forum
Home : General : Perl Programming :

Passing values from a cgi to another cgi

Quote Reply
Passing values from a cgi to another cgi
Hi,

I have a subscription form and when someone subscribes he his redirected to a "ok URL". The datas of the subscription are save to a txt file.

The "ok URL" is a link to a different cgi (not on my server), but to have it works, I need to pass the differents values from the first cgi to the second. I think I should use hidden fields, but I don't know how, as the ok URL is already a hidded field.

On the subscription cgi, I have
Code:


if ($fields{'ok_url'} ne ""){

print "Location: $fields{'ok_url'}\n\n"; exit;

}

else { &thank_you; }


and in my subscription form:

<input type="hidden" name="ok_url" value="http://www.yourdomain.com/cgi-bin/yourdata.pl">

How could I pass the entered values on the subscription form to the second cgi (on a different server)?

Thanks a lot for your help.

Last edited by:

Lotz: Jun 22, 2003, 1:38 PM
Quote Reply
Re: [Lotz] Passing values from a cgi to another cgi In reply to
Hi Lotz,

It is not very difficult. Below can work

my $extra_url = '';
$extra_url .= '&' . $_ . '=' $fields{$_} grep{!/ok_url} for keys %fields;
unless($fields{ok_url} die "I dont' know what to do :)";
print "Location: fields{ok_url}?$extra_url\n\n";

Hope that helps!

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Passing values from a cgi to another cgi In reply to
Thanks Dat,

I tried to do it, but it gives me an internal server error (error 500)...

I just added the code you gave me below, like this:

if ($fields{'ok_url'} ne ""){

print "Location: $fields{'ok_url'}\n\n"; exit;

}

else { &thank_you; }

my $extra_url = '';
$extra_url .= '&' . $_ . '=' $fields{$_} grep{!/ok_url} for keys %fields;
unless($fields{ok_url} die "I dont' know what to do :)";
print "Location: fields{ok_url}?$extra_url\n\n";

Should I change something on the code? Should I define what are the fields I need to pass (I don't need all the fields)? You just have to know that the fields are defined on the form and not in the CGI.

Thanks
Quote Reply
Re: [Lotz] Passing values from a cgi to another cgi In reply to
Hi Lotz,

Yes, you can. In the previous code, I assumed that the hash %fields contains all values of the submitted form. If you want to pass some of them to anther script, a little changes as shown below can make it worked

$extra_url .= '&' . $_ . '=' $fields{$_} for (qw/fname lastname email/);

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Passing values from a cgi to another cgi In reply to
Hi Dat,

It doesn't work. I tried to put the code you provided to me, but it gives me an internal server error...

I should make something wrong. I have:

if ($fields{'ok_url'} ne ""){
print "Location: $fields{'ok_url'}\n\n"; exit;
}
else { &thank_you; }

my $extra_url = '';
$extra_url .= '&' . $_ . '=' $fields{$_} for (qw/fname lastname email/);
unless($fields{ok_url} die "I dont' know what to do :)";
print "Location: fields{ok_url}?$extra_url\n\n";

I added

use CGI::Carp qw(fatalsToBrowser);

to see the error message, and here it is:

Software error:

Execution of /home/websites/web129/cgi-bin/subscribe.pl aborted due to compilation errors.

Any idea?

Thanks a lot, it is very important for me to have it works.
Quote Reply
Re: [Lotz] Passing values from a cgi to another cgi In reply to
Hi Lotz,

if ($fields{'ok_url'} ne ""){
my $extra_url = '';
$extra_url .= '&' . $_ . '=' $fields{$_} for (qw/fname lastname email/);
unless($fields{ok_url} die "I dont' know what to do :)";
print "Location: $fields{ok_url}?$extra_url\n\n";
exit;
}
else { &thank_you; }

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Passing values from a cgi to another cgi In reply to
Double check the "unless" line, you have a few missing brackets :)
Quote Reply
Re: [Paul] Passing values from a cgi to another cgi In reply to
Hi,

I still have the internal error server...

May be it is because of the missing brackets.

Could you please tell me where I should add the brackets.

Thanks
Quote Reply
Re: [Lotz] Passing values from a cgi to another cgi In reply to
unless($fields{ok_url}) { die "I dont' know what to do :)"; }

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln