如何将Javascript变量传递给PHP函数

时间:2019-01-07 14:43:23

标签: javascript php woocommerce

我已经在woocommerce中创建了一个付款插件- 我有一个带有字段的自定义表单。 ID号是我想在PHP函数中检索的字段。

我有一个发送OTP按钮,此按钮发布到外部API。 一切正常,我需要做的就是将文本框中的值传递给php方法。

我尝试将javascript变量分配给我尝试使用

的php变量
$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);

我只需要将该表单id输入的'idNumber'值传递给流程付款方式即可。

所有这些代码都在同一个文件中。

0 个答案:

没有答案