I want my form on a Wordpress page to be able to auto populate the "productid" & "productsku" fields from the url parameter.
The URL parameter looks like this:
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.
Kindle try below code...
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.