Title: Add PHP function
Last modified: February 26, 2018

---

# Add PHP function

 *  Resolved [dfart](https://wordpress.org/support/users/dfart/)
 * (@dfart)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/add-php-function/)
 * Hello, in my website I am implementing a virtual tpv that is in PHP and that 
   there are all the necessary data for the correct operation.
 * All the data is necessary for the signature to be calculated and to be able to
   carry out the operation.
 * I would like to know if you can help me with an improvement I want to make.
 * Currently the amount of the operation is set in the PHP, but since it will not
   always be the same amount, I would like to add a box where I put the desired 
   amount and send it to send it to PHP and redirect me to the gateway payment.
 * Could you give me a hand?
 * The PHP code to the import of the operation is `<input name="Import" type="hidden"
   value="<?php echo $Import; ?>" size="110">`

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/add-php-function/#post-10017195)
 * virtual tpv? Is that the same as virtual point of sale (virtual POS)? Where your
   app looks like a POS interface, but the transaction is relayed to an external
   payment gateway.
 * This box where you put the desired amount — is this one of the fields the gateway
   needs or is it used to calculate a different field? If it’s to calculate another
   field, you are probably looking at something in JavaScript, not PHP. When data
   is input on a form in a browser that will be sent directly to a gateway, it’s
   too late for PHP on your server to do anything. For PHP to be useful, the data
   needs to be known before the POS interface is sent out. Once sent out, you need
   JavaScript (or jQuery) to make changes to data.
 *  Thread Starter [dfart](https://wordpress.org/support/users/dfart/)
 * (@dfart)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/add-php-function/#post-10019028)
 * Yes, it is a virtual point of sale, PayPal type but it is from the bank.
 * What I would have to do is, have a box where you can enter the amount to be charged
   and when you send it, put it in the PHP line that I said before and then PHP 
   would do the job it has.
 * It is simply to have a box where to put the amount that is going to be charged
   and by clicking on the send button put that amount in the PHP so that it can 
   do the function.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/add-php-function/#post-10021672)
 * OK, but there is no PHP available where the box appears on the user’s browser.
   You could submit the value back to your server, where PHP can then get the sent
   value and configure a request to the payment gateway. Whether that’s the proper
   topology for your gateway, I could not say.
 * The other possibility is the browser submits the request directly to the gateway
   API. Then it relays the result to your server. I’m guessing it’s the former because
   then your API key can remain secret. Thus the form with the amount submits to
   a form/payment handling script on your server. This would indeed be PHP. Assuming
   the form method is POST, the amount submitted is in the $_POST array, keyed by
   the field’s name.
 * The PHP script can then configure and send a proper API request to the payment
   gateway. The script then loops, waiting for a response. The response is then 
   handled as needed.
 * An important detail is exactly where and how the form submits to the server. 
   If you do not need any WP resources, it can be any PHP file containing the form
   handling script. If you need WP resources to process the payment, your options
   are limited. The form could submit an Ajax request to wp-admin/admin-ajax.php
   instead of using the traditional form submit method. Or the form can submit to
   wp-admin/admin-post.php. This is similar to Ajax, but no jQuery is required. 
   A normal POST request will be fine. The only other option is to submit to a WP
   page that’s based on a custom template capable of handling the form submittal.
 *  Thread Starter [dfart](https://wordpress.org/support/users/dfart/)
 * (@dfart)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/add-php-function/#post-10023335)
 * Thank you very much for your response [@bcworkz](https://wordpress.org/support/users/bcworkz/)
   it has served me well. I will see the possibility of making the charges through
   another alternative or see if the fixed value can continue using it.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/add-php-function/#post-10025176)
 * You’re welcome. I’m still not sure I fully understand what you are trying to 
   do. I’m glad what I posted makes some sense. The fact remains anything a user
   enters into a form needs to be sent back to a server over HTTPS before PHP can
   do anything with it. There’s no way around that no matter what topology you are
   using.
 * If you are familiar with client scripting but new to server scripting, that important
   fact is not that obvious at first.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Add PHP function’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 5 replies
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/add-php-function/#post-10025176)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
