简体   繁体   English

如何在联系表 7 中创建动态下拉列表

[英]How do I create dynamic dropdown in contact form 7

I have a wordpress project (dqsnigeria/website/contact) and I am having a challenge of creating a dynamic dropdown menu using contact form 7. Below is the link of what I must replicate for the client.我有一个 wordpress 项目(dqsnigeria/website/contact),我在使用联系表 7 创建动态下拉菜单时遇到了挑战。以下是我必须为客户复制的内容的链接。

https://www.dqs-holding.com/en/contact-us/contact-form-general-inquiry/ https://www.dqs-holding.com/en/contact-us/contact-form-general-inquiry/

At the top dropdown that says choose a form.在顶部的下拉菜单中,选择一个表单。 If you choose one option you see a different form display until you see all options.如果您选择一个选项,您会看到不同的表单显示,直到您看到所有选项。 Some options are just common links to pages.一些选项只是页面的常见链接。 My approach to this problem is to first create different form pages but now I am stuck at using Javascript to trigger actions on different dropdown.我解决这个问题的方法是首先创建不同的表单页面,但现在我坚持使用 Javascript 来触发不同下拉列表的操作。

Could someone assist me with the code answer to this problem or a resource online where I can follow steps to achieve this task.有人可以帮助我解决此问题的代码答案或在线资源,我可以在其中按照步骤完成此任务。 Thank you !谢谢 !

First of all you need to put below code in functions.php首先你需要把下面的代码放在functions.php中

function cf7_select_dropdown($tag, $unused ) {
     if ( $tag['name'] != 'cf7-dropdown' )
         return $tag;

     $tag['raw_values'][] = "One";
     $tag['labels'][] = "One";
     
     $tag['raw_values'][] = "Two";
     $tag['labels'][] = "Two";

     $tag['raw_values'][] = "Three";
     $tag['labels'][] = "Three";

     $pipes = new WPCF7_Pipes($tag['raw_values']);
     $tag['values'] = $pipes->collect_befores();
     $tag['pipes'] = $pipes;

     return $tag;
}

add_filter( 'wpcf7_form_tag', 'cf7_select_dropdown', 10, 2); 

Now use "cf7-dropdown"现在使用“cf7-dropdown”

[select cf7-dropdown]

That's it, now you will see custom values in dropdown.就是这样,现在您将在下拉列表中看到自定义值。

you can populate woocommerce products in contact form 7 select.您可以在联系表格 7 选择中填充 woocommerce 产品。

visit this link article for more details https://lets-solve.com/populate-woocommerce-products-in-contact-form-7-select/访问此链接文章了解更多详情https://lets-solve.com/populate-woocommerce-products-in-contact-form-7-select/

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

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