dongzan7016 2017-09-11 00:36
浏览 456
已采纳

从URL参数自动填充输入表单字段

I have a button on a woocommerce page (http://.../product/abcd/) that has a button "Book Appointments Now" that links to another page with form fields to submit (http://.../booking-appointments/?id=1238&sku=1) which has ProductID and SKU on the URL of that product from the previous page.

I want it to auto-populate the ProductID field automatically each time this page loads from the URL parameters.

Any help is appreciated.

  • 写回答

2条回答 默认 最新

  • dongmei8460 2017-09-11 01:02
    关注

    To auto populate the product ID and the product SKU in your booking form (page), you should try this (without any guaranty as it can be tested for real on your page form):

    add_action( 'wp_footer', 'autopopulate_product_id_script' );
    function autopopulate_product_id_script() {
        if( isset( $_GET['id'] ) ):
            ?>
            <script type="text/javascript">
            (function($){
                $('input[name="productid"]').val("<?php echo $_GET['id']; ?>");
                $('input[name="productsku"]').val("<?php echo $_GET['sku']; ?>");
            })(jQuery);
            </script>
            <?php
        endif;
    }
    

    Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    The product id and the product sku need to be passed in url something like: http//www.example.com/booking-page/?id=124&&sku=AH1584

    And your <imput> text fields should be something like:

    <input type="text" name="productid" val="">
    <input type="text" name="productsku" val="">
    

    So for the product sku is something similar, that you will be able to add with ease…

    But as javascript is already very active in you "Easy Appointments" booking form, I don't know if this will work.


    This answer is related to: Add custom "Booking" button to WooCommerce Product single pages

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?