I have a custom paypal cart and before i get redirected to paypal to buy the items, i want in background to send automatically an email with cart items (item title, address, image link).
This is the paypal form
<div id="thebasket">
<form method="post" action="https://www.paypal.com/uk/cgi-bin/webscr">
...
<input type="submit" value="Buy Now" class="pplbuynowbtn">
</form>
</div>
this is is the js
$(theDiv).html(theform).ready(function () {
$(this).find('input').keypress(function (e) {
if (e.which == 13) {
var thisitem = $(this).attr("name");
var thisval = $(this).val();
$(theDiv).PayPalCart('update', thisitem, thisval);
return false;
}
});
});
Now if I press buy now, is going to paypal.com and i can't get his address and the item image from there. This is why I need this email before paypal.
Any help, please?
I think submitting two forms will be a bad idea.
There are two methods:
1. AJAX
Display a submit button that triggers a AJAX call that submits your mail, as the ajax request is completed now trigger the JS function to submit the second form for paypal.
2. PHP
You should trigger a PHP script on SUBMIT, which contains:
<?php
function form()
{
//form submitting that sends shipping data
}
function paypal()
{
//curl script for form posting
$url = 'https://www.paypal.com/uk/cgi-bin/webscr';
$data = array('amount' => '50');
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded
",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);}
?>
Display a fake submit button "Buy Now" that triggers an Ajax call sending the email, then use $('#thebasker form').submit()
in successful Ajax callback to validate your Paypal form.