大佬教程收集整理的这篇文章主要介绍了php – Gravity Forms – 获取当前页码,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在此表单的最后一页上执行一些自定义JavaScript.从理论上讲,我所要做的就是检索当前页码并编写条件.
简单吧?显然不是.
if ($('gform_page').last().css('display') !== 'none') { // perform custom scripts Now that the last // Gravity Form page is being shown }
但是$(”’).css(‘display’)在我在表单中尝试过的每个元素上返回undefined.每次用户点击“下一步”按钮时,都会触发自定义脚本.没有雪茄.
然后,在回顾the Gravity Forms documentation之后,我发现了两个有用的事件:gform_post_render和gform_page_loaded.
但是,文档未提供有关如何访问参数的说明.
jQuery(document).bind('gform_page_loaded',function(event,form_id,current_pagE){ console.log(current_pagE); // returns nothing when loaded in the footer // returns [Object,object] when placed in an HTML field in the form });
除了没有正确的代码之外,我还怀疑我没有正确的代码,因为我还在functions.PHP和header.PHP(as the documentation suggests)中尝试了以下内容:
<?PHP function enqueue_custom_script($form,$is_ajaX){ if ($is_ajaX) : echo '<script>console.log(current_pagE);</script>'; endif; } add_action("gform_enqueue_scripts","enqueue_custom_script",10,2); ?>
题:
显然,功能rgpost
在访问当前页码时至关重要.经过我自己的一些混乱之后,我能够在functions.PHP和header.PHP中的wp_head()函数之前获得以下代码.
function run_script_on_last_page($form) { if (!is_admin()) { $current_page = rgpost('gform_source_page_number_' . $form['id']) ? rgpost('gform_source_page_number_' . $form['id']) : 1; if ($current_page == 10) { wp_enqueue_script('custom_script',get_template_directory_uri() . '/js/custom_script.js',array('jquery'),null,truE); } } } add_action('gform_enqueue_scripts_63','run_script_on_last_page');
如果您要复制/粘贴上述代码,请务必:
>将10替换为您要检查的页面
>确保wp_enqueue_script中的参数正确
>用表格ID替换63
我认为有用的一些资源:
> g001_validation过滤器文档的this section
> gform_enqueue_scripts
的文档.
以上是大佬教程为你收集整理的php – Gravity Forms – 获取当前页码全部内容,希望文章能够帮你解决php – Gravity Forms – 获取当前页码所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。