I have a form on my website and depending on if the user check paypal or wire-transfer the form action should always go to functions.php where I have this simple check at the end of the file:

if ( isset( $_POST['submitted'] ) && isset( $_POST['post_nonce_field'] ) && wp_verify_nonce( $_POST['post_nonce_field'], 'post_nonce' ) ) {



So, my question is how do I do some stuff using an if condition in my functions.php before posting the form to PayPal?

Because all tutorials have form action https://www.sandbox.paypal.com/cgi-bin/webscr

How could I send all the post info from the formular (I can grab the values and stoere them in variables) via this address https://www.sandbox.paypal.com/cgi-bin/webscr?

Is it somehow possible doing this and not using form to send the values there?

Does WordPress have any function to send post request to a distant url?


This isn't really a wordpress issue and will probably get a better response be in the Stack Overflow PayPal page: https://stackoverflow.com/questions/tagged/paypal

However, from what I've understood of your question, you want to know how to pass values from your form to PayPal?

To do this, you need to populate hidden fields and 'send' these to the PayPal address using the form post method.

The following link should help you out: https://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/howto_checkout-outside#methodtwo

If this isn't what you're looking for, tell us what conditions you wish to check for in your functions file and we may be able to help you further.

| improve this answer | |
  • I know about the hidden fields, that's not an issue. I know that I need the post method, but I don't want to use form. Because I need to make some value changes in functions/php and after taht send results to paypal via post method. Does wordpress offer me such function? – Derfder Sep 3 '13 at 11:19
  • Not really - you're going to need to write some functions in PHP (which will go into your Wordpress functions.php file). We still don't know what you're trying to do though so need more information to guide you in right direction. – TomC Sep 3 '13 at 11:28
  • I am looking for some curl alternative build in WP. – Derfder Sep 3 '13 at 13:26
  • Why do you need curl? I can't work out what you're trying to do so I can't tell you what you need, but I doubt it's the curl library – TomC Sep 3 '13 at 13:38
  • of course not. But I would need to use fopen and stuff. Iagine you have a variable $color = 'green'; and you want to send this variable as a post method. How would you do that from a script and not from a form? – Derfder Sep 3 '13 at 15:04

First off, move that code from the bottom of your functions.php file into a function that hooks into wp_init (still inside functions.php, though). Check for nonces / form submission in that function instead. Its almost the same thing (I think theme functions.php files are loaded in wp_init) but it is definitely the more Wordpressy way to do things and its less inclined to nuke your entire site in the future.

After that, you will have to use curl or a PayPal class that wraps the necessary curling. There's no way around this and its out of the scope of Wordpress. If you need more help with this, I would ask another question on normal Stackoverflow.

| improve this answer | |

There are a couple of ways to approach this:

cURL Method

Submit via cURL by submitting your form to <form action"<?php echo get_template_url; ?>/form_processors.php" method="POST"> In that file you would sanitize inputs and make your cURL call and submit that via POST. You could also use wp_remote_post() here which will be more robust on servers that may not have cURL installed if that's a concern.

AJAX Method

This article should cover what you're trying to do on the PayPal side, and should be easy enough to modify for the wire transfer option. http://code.tutsplus.com/tutorials/a-guide-to-the-wordpress-http-api-payments-with-paypal--wp-25137

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.