0

i have created a payment plugin in woocommerce- i have a custom form with fields. ID number is the field i am wanting to retrieve in the PHP function.

i have a send OTP button this button post to an external API. everything works all i need to do is pass the value in the textbox to a php method.

ive tried assigning the javascript variable to a php variable i tried using

$POST['textboxID'], i also tried using $GET['textboxID']

public function payment_fields()
    {


        if ($this->description) {



            echo wpautop(wp_kses_post($this->description));

        }




        do_action('woocommerce_credit_card_form_start', $this->id);



       // add_action('woocommerce_after_order_notes','idNumber');
        $float = WC_Payment_Gateway::get_order_total();
        $grandTotal = number_format((float)$float, 2, '.', '');
        $username = $this->get_option('publishable_key');
        $password = $this->get_option('private_key');


         echo '<div  id="custom_input" class="form-row form-row-wide">
        <form method="post" name="myform">
                <table>
                <tr>
                <td>
                <label >ID Number : <span class="required">*</span></label>

                </td>
                <td>
                <input id="idNumber" name="idNumber" type="text" value="" style="width:224px;margin:-30px -59px" autocomplete="off">



public function process_payment($order_id,$CardOrIDNumber)
    {   
        global $woocommerce;
        $order = new WC_Order($order_id);



        $float = WC_Payment_Gateway::get_order_total();
        $data3 = openssl_random_pseudo_bytes(16);
        $data3[6] = chr(ord($data3[6]) & 0x0f | 0x40); // set version to 0100
        $data3[8] = chr(ord($data3[8]) & 0x3f | 0x80); // set bits 6-7 to 10

        $GUID = vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data3), 4));

       $idNumber = $GET['idNumber'];
       print_r($idNumber);

i just need to pass that form id input 'idNumber' value to the process payment method.

all this code is in the same file.

  • You'd have to use AJAX (or sockets I guess) to indirectly call a PHP function from JS. As an aside, it's `$_POST` and `$_GET`. – Jonnix Jan 07 '19 at 14:44
  • You can store the js variable value in a cookie and later access that variable in php cookie as answered here - https://stackoverflow.com/a/35684778/5729813 – Tushar Walzade Jan 07 '19 at 14:46
  • even if i want to pass the value from javascript to PHP- – Radhiyah Williams Jan 07 '19 at 14:47
  • 2
    Possible duplicate of [How to pass JavaScript variables to PHP?](https://stackoverflow.com/questions/1917576/how-to-pass-javascript-variables-to-php) – Tushar Walzade Jan 07 '19 at 14:47
  • PHP runs on server side, javascript runs on client. So you need to make ajax call to your back-end to send variable. – maximelian1986 Jan 07 '19 at 14:48
  • https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming may also be relevant. – Jonnix Jan 07 '19 at 14:49
  • I dont see any javascript here, just a standard form submit, and incorrectly accessing the form post variable. Maybe I'm confused by the question and code supplied, because its all color-coded wrong and chopped up. – IncredibleHat Jan 07 '19 at 14:56
  • @IncredibleHat this code is done in woocommerce/wordpress. the 1st section is the form and the javascript combined thats the 1st method. this is a woocommerce plugin with a form – Radhiyah Williams Jan 07 '19 at 15:02

0 Answers0