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

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

Replies are listed 'Best First'.
Re^8: Coding and Design Advice
by b310 (Scribe) on Apr 01, 2005 at 16:51 UTC
    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.
Re^8: Coding and Design Advice
by Anonymous Monk on Apr 01, 2005 at 17:47 UTC
    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.
      It might be possible to twiddle the URL called by the redirect header. Can you post the code that constructs the paypal button on your page? - the original page was offline last time I tried.

      I also am offline for a while, but I'll take a look at this again tomorrow GMT.

      Update: The original page is back online, and there's a possible solution. Its a bit krufty - someone might be able to come up with a cleaner approach, perhaps using javascript to change the form action from the client side, but this seems to work OK. Change your redirect URL to:

      https://www.paypal.com/cgi-bin/webscr?add=1&cmd=_cart&business=MAILADDRESS&item_name=BridgeMill%20Power%20Tennis%20Camp&name=item_number=Camp05&amount=198.00&no_note=1&currency_code=USD&lc=US

      This is the URL taken from the form action, with all the fields that were supplied as hidden form parameters in the html source supplied as URL parameters.

      (You'll need to change the mail address to the correct one - I chopped it to combat spambots). You might also need to check your agreement with paypal to make sure you aren't obliged to display their button.

      Hope this helps.

      g0n, backpropagated monk
        Hi,

        I think I was able to figure out my problem. Here's the flow of my script, person views static web HTML page with form -> they complete the form -> select their payment option -> click Submit. The submit action calls in my script camp.cgi.

        In this script, I did the following conditional:

        If payment option is equal to a or b -> generate confirmation page to print for records, send confirmation email, and a third email to the person hosting the event.

        If payment option is equal to c (credit card) -> send confirmation email to person, send email to person hosting event, and finally generate a paypal page which contains the HTML code and PayPal button which I got directly from PayPal.

        I ran the script with option c and when I clicked the Add to Cart button which directs you to PayPal, I was actually directed to PayPal. I was able to view my cart and go to checkout. So I think I'm ok. I'm not quite sure how I came up with this. It dawned on me during the middle of the night.