user1596138
user1596138

Reputation:

How can I submit one form and then submit information to paypal for payment?

this is my first question here....

So I run all IT related things for a local entertainment paper and ad business. We sell classified ads by the word both through mail from our paper and online. Before I came they would simply have people put they're ad info in, do they're OWN math and then tell us how much they owe, a hassle they shouldn't be going through. But what's worse is they would just enter in they're Credit Card info in a few input field which were then mailed to us when they submitted the form to our web hosts cgi system...... Terrible idea I know.

So far i've completely redone the website with php and have my form looking nice and neat, it does all word counting/math for the customer and then copies the end amount due from readonly fields into my hidden "amount" variable for the paypal buy it now button (Obviously we want to use paypal to recieve payments now..). My problem is that the button submits a form with the needed information to paypal which brings up the buy it now screen with the new price, but my other form needs to be submitted and emailed to me at the same time they go to paypal, I don't need payment to be verified before I get the info I can just trash the ones that don't pay.

Each form works perfectly when used independently, how can I have the info emailed to me and then submit another form to paypal so the price comes up? I'm new... but i have a great understanding of JS so if that's the solution, great. Any help will be greatly appreciated.

In case it helps here is a link to the .php file containing the forms. I did remove the email and action information as well as our paypal business ID just because.... I don't want random forms submitted to our email and I don't want anything weird with paypal haha. Anyway heres the link http://www.whatzup.com/content/diningclub/classified2.php

My code is probably messy and unprofessional but I'm 17 and am learning as I go with this job and my boss knows that. With that in mind any pointers/tips on ANYTHING would be great. All the javascript in the top is either word counting stuff or something I was experimenting with trying to get this to work. I will put my final JS into it's own file and include it in the header like i did the math file.

Edit: I'm REALLY stumped here and if we can't get this to work I'll have to have the one form popup in a new window when they submit which tells them to go back to the other page and pay with Paypal... Which would be pathetically unprofessional.

Upvotes: 2

Views: 3294

Answers (2)

user1596138
user1596138

Reputation:

Here's what I did incase anyone else wonders. The first form submits to this php script, which contains a new form and uses the data from the old one to fill the amount section. Then if the form sent successfully the second is submitted with JS.

Using no delay you could send multiple forms like this, although not technically from one page it would appear that way to the user.

 <script type="text/javascript">

function submitt()
{
setTimeout('document.paypal.submit()',1000);
}
</script>


<?php
$Amount  = $_REQUEST['amount'];
$to      = "XXXX";
$from    = $_REQUEST['email'];
$name    = $_REQUEST['Name'];
$headers = "From: $from" . PHP_EOL;
$subject = "Classified Ad submission";

$fields                         = array();
$fields["Name"]                 = "\nName";
$fields["email"]                = "\nEmail";
$fields["Phone"]                = "\nPhone";
$fields["WorkPhone"]            = "\nWork Phone";
$fields["Address"]              = "\nStreet Address";
$fields["City"]                 = "City";
$fields["State"]                = "State";
$fields["Zip"]                  = "Zip Code";
$fields["Classification"]       = "\nClassification";
$fields["Ad-Headline"]          = "\nHeadline";
$fields["Other-Classification"] = "\nAlternate Classification";
$fields["Ad-Content"]           = "\nAd Content";
$fields["Words"]                = "\nWord Count";
$fields["Weeks"]                = "\nWeeks to Run";
$fields["WordCount"]            = "\nTotal Words";
$fields["Rate"]                 = "\nWord Rate";
$fields["GrossAmountDue"]       = "\nGross Amount";
$fields["NonProfit"]            = "\nNon Profit Ad?";


$body = "This Ad has been submitted:\n\n";
foreach ($fields as $a => $b) {
    $body .= sprintf("%20s: %s\n", $b, $_REQUEST[$a]);
}

if ($from == '') {
    print "You have not entered an email, please go back and try again";
} else {
    if ($name == '') {
        print "You have not entered a name, please go back and try again";
    } else {
        $send = mail($to, $subject, $body, "From: XXXX" . PHP_EOL);
        if ($send) {
            print "Thank you $Name, your Ad has been submitted, redirecting to paypal.";
            echo "<SCRIPT LANGUAGE='javascript'>submitt();</SCRIPT>";
        } else {
            print "ERROR";
        }
    }
}


?> 

<form action="https://www.paypal.com/cgi-bin/webscr" id="paypal" onClick="sendtotal()" target="_top" name="paypal" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="XXXXXXXXXXX">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="Classified Ad">
<input type="hidden" name="amount" value="<?php echo $_POST['amount'];?>" />
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="cn" value="Add special instructions to the seller:">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="shipping" value="0.00">
</form>

Upvotes: 1

Sire
Sire

Reputation: 4378

If I understand correctly, the problem is that you want the customer to pay with PayPal and mail you at the same time? And then possibly send you an email when payment is complete.

The simple way is to use a "success page" and a "cancel page" that the customer ends up on after payment is complete or cancelled.

You can add this by editing the button, under advanced features: "Take customers to this URL when they finish checkout"

Here you can also check "Add advanced variables" so you can add an unique identifier or email of the customer.

On these two pages you can easily send your email.

The correct way is to use Instant Payment Notifications (IPN) but I suggest you try the simple method first.

Upvotes: 1

Related Questions