views:

99

answers:

2

I have a problem with a form. I need it to perform two actions with only one submit click. I've read that the best solution is a server-side script, but my knowledge of PHP is pretty limited, so I'd really appreciate any help.

The two actions I need to perform are:

  1. Run a script that uploads a file and sends an email (action="uploader.php")
  2. Direct the user to a PayPal payment gateway (action="https://www.paypal.com/cgi-bin/webscr")

As I see it, the problem is that I don't have control over the PayPal script, but it obviously takes some data from the form (i.e. amount, concept, etc...), so adding a simple redirect in uploader.php isn't enough.

What do you think? How could I solve it?

Thanks!

UPDATE: I'll try to post the user-action flow:

  1. user fills in the form and adds a file to upload
  2. 1st form action: file is uploaded and an email is sent (action="uploader.php")
  3. 2nd form action: user is taken to a paypal payment form (action="https://www.paypal.com/cgi-bin/webscr")
  4. When the purchase is completed the user is taken to a purchase confirmation page.
+1  A: 

Your uploader.php should show the new paypal form (or the same) to user and submit it by javascript on dom ready. Don't forget about non-javascript users too.

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="myForm">
  <!-- obviously hidden input's -->
  <script type="text/javascript">
    window.onload = function(){
      document.getElementById("myForm").submit();
    }
  </script>
  <noscript><input type="submit" value="Continue to Paypal!" /></noscript>
</form>
Anpher
I apologize, but I don't follow. Maybe it is because in your answer you assume that I know more than I actually do...I don't see a reference to the 1st action I need to perform (run uploader.php).I've updated the original question with some more info.Thanks for your help!
JMin
@JMin "running" uploader.php happens when you submit the form to it. A PHP script is run when it is requested. A form submit just requests a PHP page with some POST parameters. Anpher is suggesting that your uploader.php script outputs (`echo`) the code he posted in his answer, and that the javascript (which he also provided) automatically submits the generated form to paypal.
Carson Myers
What I was trying to say is that you can't submit one form to two or more urls ar once. You have to do this one by other. form -> uploader.php -> form -> paypal
Anpher
Thanks a lot Anpher for your solution and thank you Carson Myers for your explanation too. It worked wonderfully!
JMin
A: 

You can send the form to submit.php, upload your file, perform your email action, then use CURL to send your data on to PayPal.

This site has an example of how to send data to PayPal via CURL/PHP:

http://curl.phptrack.com/forum/viewtopic.php?p=9643&amp;sid=5cc0c394df6efcf73772273846430fbe

jnunn
Thanks for your answer. After reading the link you posted the other solution seemed easier for me.
JMin