我正在寻找一种向CF7表单添加条件逻辑的方法。我偶然发现了一些插件,但是那些我发现的插件似乎缺少了我正在寻找的功能。
我希望根据下拉菜单的条件来更改隐藏字段的值。
示例用例:
如果语言-下拉=“西班牙语”将textfield1设置为“/file目录/for/西班牙语/templatefile”
如果视频类型下拉=“开放式促销”,则将textfield2设置为“查看”。
我希望有人能为我指出正确的方向,以便实现这一点。
致以良好的问候,丹尼
发布于 2019-11-08 09:35:41
实现这一目标的唯一方法是使用自定义脚本文件。
使用functions.php文件中的以下后端函数在加载窗体的页面上加载脚本,
add_action( 'wp_enqueue_scripts','register_custom_script');
//its important to register the script, else it will not load properly.
function register_custom_script(){
wp_register_script( 'custom-cf7-script', , array( 'jquery' ), null, true );
}
add_filter( 'do_shortcode_tag','load_custom_script', 10,3);
function load_custom_script($output, $tag, $args){
if('contact-form-7' != $tag){
return $output; //not a cf7 form shortcode.
}
if(!isset($attr['id']) || != $attr['id']){
return $output; //not your form
}
//load your custom script that you previously registered.
wp_enqueue_script( 'custom-cf7-script');
}在您的自定义脚本中,您可能会想做一些类似的事情,
(function($){
$(document).ready(function(){
var $select = $('#language-drop-down');
var $hidden = $('#textfield1');
$select.on('change',function(){
if("spanish"==this.value) $hidden = "/filedirectory/for/spanish/templatefile";
});
})
})(jQuery)https://wordpress.stackexchange.com/questions/352129
复制相似问题