skip to Main Content

first of all, I need to tell you that my php knowledge is very low.

I’m using a WordPress plugin called WP User Frontend and I’m charging users to post articles inside my website: after filling up the form, the user clicks on a "Submit" button and it is redirected to a payment page inside which the plugin handles the payment, calling a php var $pay_per_cost.

The thing is that this aforementioned $pay_per_cost var is a static value determined by myself using the plugin settings, but I would like to make it dynamic: I would like the user to be able to choose from different radio or checkbox inputs and update the posting cost based on some different services that the website offers (in addition to the standard posting fee). I already have found the way to update the radio/checkbox cost via jQuery, but I don’t know how i can pass this JS var that I created listening to the input fields updates to the $pay_per_cost php var.

The only thing I can tell you is that the posting page (which includes the inputs and the JS cost var) and the payment page (which calls up the php $pay_per_cost var) are two different pages.

Can you help me out with this?

Edit: in the first page (the one that contains the inputs and the JS) there is already a form, which actually is the main form (the one that catches the user data for the user post to be published inside my website).

2

Answers


  1. If I understood correctly what you said, your problem might be solved using a form in HTML. If you put the inputs in a form tag, and you add a submit button, you can accomplish what you need.

    Basically, the submit button will send the input’s value to another page (or the same, if wanted), and you’ll be able to access it via PHP (using the global var $_GET or $_POST, depending on the method you used).

    So, supposing we have this:

    <form method="get" action="/link/to/the/page/where/you/want/to/receive/data">
         <input name="idValue">
         <button type="submit">Submit!</button>
    </form>
    

    In your PHP file, where you want to read the data, you could just do this:

    $pay_per_cost = $_GET['idValue']
    

    And your var would have the value that the user inserted in the form.

    If you need to, specifically, send a variable that you have in JavaScript, I only have one idea: using JavaScript, add an element to the form and hide it (for example, with display:none). If you add an input to the form using JS and you give to it the value you want to send, when the user presses the submit button, that value will also be sent.

    Login or Signup to reply.
  2. PHP is executed on the server side, were JS is executed on client side. Hopefully their is 2 way to work on it.

    The first way is as @Tupi answer, via a form.

    The other way is by making it via an AJAX request all in javascript, to a page in PHP that will change the values you want.

    And to answer something you seem to fear in comment, if you do it right, no, your new form and the current one shouldn’t mess with each other… unless you do something terribly wrong.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search