Submitting form data to two locations using Javasc

2019-08-07 12:33发布

I have an order form that has several text areas and a single PayPal "Buy Now" submit button. I would like the PayPal button to work like usual, submitting the order to PayPal, but I would also like the same button to collect the data in the form and send it off in an email. In order to do that, though, the button would need to have two actions: sending data to PayPal, and sending data back to my php page.

It seems like this is a common problem, with no clear solution yet using solely PHP. Since I only need the data from the forms, I thought I could grab that with Javascript. I thought I could put an onClick event on the paypal button, which would call a JavaScript function that contains the PHP needed to send an email.

Is this possible? Am I way over-thinking this?

EDIT Ok, so I don't want to dig into the PayPal API, since I am not comfortable with PayPal to begin with. I am thinking of another solution, which has not yet worked, but it might have potential.

The standard PayPal button code uses an input type="image" for the button. I am placing a link element around that input tag, and linking to a javascript function. For example:

<a href="javascript: submitForm()"> <input type="image src= ...> </a>

I have a form set up like this:

<form name="userInfo" action="sameFile.php" method="post">

Where "sameFile.php" is just the name of the current php file this line resides in.

Then elsewhere in the same code file I have:

<script type="text/javascript"> function submitForm(){ document.forms["userInfo"].submit();}</script>

Where userInfo is the form with all my user input boxes. Note that "userInfo" is NOT the form which contains the PayPal button, so that might be the problem...

Anyway, this all seems to work, though I have no idea if the PayPal order is going through or not. I just get redirected back to the same php page.

Next I want to use PHP to extract the data that SHOULD be in the POST array. I enter a few test echos reporting the POST values, but the page does not load at all once I add this code. What am I doing wrong? Is there a specific place I should be putting the PHP that parses the data from the forms?

1条回答
乱世女痞
2楼-- · 2019-08-07 12:58

Do you want to send a order completion mail ?

If so, write code to send mail in success page of paypal(return page in your server) - This is the actual way of doing it.

查看更多
登录 后发表回答