简体   繁体   English

在Wordpress页面上自动填充表单脚本

[英]Auto-populate form script on Wordpress page

I want my form on a Wordpress page to be able to auto populate the "productid" & "productsku" fields from the url parameter. 我希望我的Wordpress页面上的表单能够从url参数自动填充“ productid”和“ productsku”字段。

The URL parameter looks like this: URL参数如下所示:

http://.../?productid=1680&productsku=1

My current script works on my other form pages but not this page. 我当前的脚本可以在其他表单页面上运行,但不能在此页面上运行。

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

Any help is appreciated! 任何帮助表示赞赏!

In your code, java script code is not working when the action is called. 在您的代码中,调用动作时Java脚本代码不起作用。
Kindle try below code... Kindle尝试以下代码...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM