How to send form values from the script in functions.php and not from the form on my website?

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' ) ) {

// CODE AFTER SUBMIT HERE 

}

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?

Topic paypal forms Wordpress

Category Web


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


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.


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.