in reply to Re^4: Coding and Design Advice
in thread Coding and Design Advice

The HTTP redirect using CGI is quite straightforward:

use CGI; my $cgi = new CGI; print $cgi->redirect('http://thisistheurltoredirectto.com');

You will need to do your redirect conditionally upon the content of $cgi->param('paymenttyperadiobutton') and remember that the redirect has to be the first header - don't issue a standard http header beforehand.

g0n, backpropagated monk

Replies are listed 'Best First'.
Re^6: Coding and Design Advice
by b310 (Scribe) on Apr 01, 2005 at 12:13 UTC
    Hi,

    Yes, it certainly appears straightforward. I also understand that the redirect will be based on the result of the button that is selected.

    As for placing the redirect as the first header, do I place it before my conditional statement or after?

    I'm not sure I follow "has to be the first header".

    Thanks.
      OK, the code will be something like:

      #!/usr/bin/perl use strict; use CGI; my $cgi = new CGI; # construct and send confirmation emails here if you # want them to go to everyone if ($cgi->param('radiobutton') eq 'paypal') { # this sends a redirection header print $cgi->redirect('http://sendmetopaypal.com'); } else { # construct and send confirmation emails here if you # only want them to go to non paypal users print $cgi->header(), $cgi->start_html, "Thank you for booking, a confirmation email has been sent to +email\@address", $cgi->end_html; }

      What I meant by 'has to be the first header' is don't do this:

      #!/usr/bin/perl use strict; use CGI; my $cgi = new CGI; print $cgi->header; print $cgi->redirect('http://redirecttohere.com');

      I've got stuck on that one a couple of times :-) In other words, don't forget that redirect is a header in it's own right - it doesn't need a $cgi->header sending before it.

      g0n, backpropagated monk
        Hi,

        Thank you for your reply. I assumed the exact scenario you mentioned at the end. I was thinking of doing what you said not to do.

        Thank you for your help.
        Hi,

        I believe I found one loophole with the redirect solution. PayPal provides a button which contains all the parameters which are needed to charge the persons credit card and place the money into the account of whom is receiving the payment.

        The way the current redirect statement is written it will take me to PayPal, but it won't pass any of the parameters for the event which need to be charged to the persons credit card.

        The PayPal button must be clicked first in order to be directed to PayPal. As I can tell, I don't think I'll be accomplishing this with the current code.