我可以在 WordPress 中使用 Contact Form 7 插件来设置条件字段吗?
我想要的很简单。
用户可以选择 A 或 B,根据此,他们需要填写不同的字段。
我找不到这样做的方法,我只找到了 1.0 版本的 hack(当前是 2.4.6)
What I want is simple.
User can select A or B and depending on this, they have different fields to fill.
I can't find a way on doing this, I've only found a hack for the 1.0 version (current is 2.4.6)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我刚刚编写了一个 WordPress 插件,为 Contact Form 7 添加了条件逻辑。
源代码位于 github 上:https://github.com/pwkip/contact-form-7-conditional-fields
您可以从此处的 WordPress 存储库下载该插件:https://wordpress.org/plugins/cf7-conditional-fields/
I've just written a WordPress plugin that adds conditional logic to Contact Form 7.
The source code is on github: https://github.com/pwkip/contact-form-7-conditional-fields
You can download the plugin from the wordpress repository here: https://wordpress.org/plugins/cf7-conditional-fields/
这个问题最初应该发布在Stack Overflow 的 Wordpress 页面下。您可能会得到更快的答案。 :)
这是答案。 :D
我知道这个问题很久以前就被问过,但我也找到了解决方案,因为我自己也在寻找这个问题。因此,对于其他可能也在寻找解决方案的人来说,这是答案。下面列出的链接对我帮助很大。
“使用联系表单 7 有条件地显示/隐藏字段”
This question should have been posted under Stack Overflow's Wordpress page initially. You probably would have gotten a quicker answer. :)
Here is the answer. :D
I know this question was asked quite a while back but I have also found a solution to it as I was looking for this myself. So here is the answer for anyone else who might also be looking for a solution. The link listed below has helped me tons.
"Show / Hide Fields Conditionally with Contact Form 7"
随着 CF7 4.1 于 2015 年 1 月左右发布,这种情况发生了变化。有关更改的详细信息可以在这里找到 -
http://contactform7.com/2015/01/06/ contact-form-7-41-beta/
代码应如下所示 -
This changed with CF7 4.1 release around 1/2015. Details on the changes can be found here -
http://contactform7.com/2015/01/06/contact-form-7-41-beta/
Code should look something like this -
@jules-colle 的 CF7 条件字段显然是一个很棒的解决方案。
但是,如果您想有条件地显示/隐藏一两个字段,添加一些内联 js 效果非常好。
以下是 CF7 表单生成器的示例副本:
要进一步阅读和更多示例,请检查 我关于此主题的文章。
The CF7 Conditional fields by @jules-colle is an obvious awesome solution.
However, if you want to conditionally show/hide one or two fields, adding some inline js works very well.
Here is an example copy of the CF7 form builder:
For further reading and more examples, check my article on this topic.
如果您想要的不仅仅是隐藏/显示元素,您可以查看我的这篇文章: 这是如何使用 jQuery 在 CF7 中模拟条件字段。
有关您可以做什么的现实示例,您可以查看 此网站 选择“Richiediquotazione”选项卡。该网站是意大利语,但很容易给您一个想法...
回到我的文章,给出的示例基于您在现实生活中可能有复杂条件的假设(例如:您销售的产品可以是标准的,但是也可定制)。
对应预先设定的形状、宽度和高度,然后让用户
仅输入所需的长度。我还想显示形状的预览。
长度。
前提是您可以安全地处理您的儿童主题,所以如果您仍然不这样做,请立即执行!
该代码引用了一个 ipotetical 子主题 url
/wp-content/themes/myTheme-child
及其子目录/catalogue
和/js
域名my-domain.it
。您必须根据您的 WordPress 安装更改这些值。第 1 步:建立您的联系表单。对于给定的示例,我构建了一个:它假设您的子主题的
/catalogue
子目录中有一个myCatalogue.pdf
文件。这是...第 2 步:使用适当的 CSS 指令集设置您的联系表单的样式。我的也包含一些管理我通过 jQuery 添加的类的指令。就是这样...
第 3 步:写下一些管理脏工作的函数。我负责检查条件,显示/隐藏适当的字段,预设值,用灰色信息框替换预设字段,显示产品形状的预览。您必须将其作为
Cond1.js
保存到子主题的/js
子目录中,以使其适用于给定的示例。您还需要将一些.jpg
保存到子主题的/catalogue
子目录中,以便产品形状预览正常工作。这是代码...第 4 步:将 jQuery
Cond1.js
文件排入您需要的页面/帖子或页面/帖子上。我准备了以下代码,将其添加到您的子主题的functions.php
中:它假设您将表单放入页面 id 1;根据您的需要更改此设置。这是代码...仅此而已。
You can check this article of mine, if you want something more than simply hide/show elements: This is how to have simulated conditional fields in CF7 with jQuery.
For a real-life sample of what you can do, you can check this site selecting the tab "Richiedi quotazione". The site is in Italian, but easily gives you an idea...
Back to my article, the example given is based on the assumption you can have complex conditions in real-life cases (e.g.: you sell products that can be standard, but can also be tailored).
correspond pre-set shape, width and height, and then let the user
input only the desired lenght. I also want a preview of shapes to be shown.
lenght.
Premise is that you work safely on your child-theme, so if you still don't, do it now!
The code refers to an ipotetical child theme url
/wp-content/themes/myTheme-child
and to its subdirectories/catalogue
and/js
within the domainmy-domain.it
. You will have to change these values accordingly to your wordpress installation.STEP 1: build your contact form. For the given example, I built one: it assumes you have a
myCatalogue.pdf
file into the/catalogue
subdirectory of your child theme. Here it is...STEP 2: style your contact form with an appropriate CSS set of directives. Mine contains some directives to manage classes I add via jQuery, too. Here it is...
STEP 3: write down some functions to manage the dirty job. Mine take care of checking the conditions, show/hide appropriate fields, pre-set values, substitute pre-set fields with grayed info boxes, show a preview of the product shape. You will have to save it as
Cond1.js
into the/js
subdirectory of our child theme to make it work with the given example. You will also need to save some.jpg
into the/catalogue
subdirectory of your child theme for the product shape preview to work properly. And here's the code...STEP 4: enqueue the jQuery
Cond1.js
file on the page/post or pages/posts you need. I prepared the following code to be added to thefunctions.php
of your child theme: it assumes you put the form into page id 1; change this accordingly to your needs. Here's the code...That's all.
您可以使用此插件来填写联系表格7。
https://wordpress.org/plugins/cf7-conditional-fields/
这个插件向联系表单 7 添加了条件逻辑。
如果您编辑 CF7 表单,您将看到一个名为“条件字段组”的附加标签。默认情况下,您在开始标签和结束标签之间放置的所有内容都将被隐藏。
添加字段组后,单击“保存”并转到“条件字段”选项卡,创建一个或多个使字段组出现的条件。
您也可以观看联系表单 7 条件字段教程 https://www.youtube 的视频
。 com/watch?v=1AQEmecb0l4
You can use this plugin for contact form7.
https://wordpress.org/plugins/cf7-conditional-fields/
This plugin adds conditional logic to Contact Form 7.
If you edit your CF7 form, you will see an additional tag called “Conditional fields Group”. Everything you put between the start and end tag will be hidden by default.
After you have added the field group(s), click Save and go to the “Conditional fields” tab to create one or more conditions that will make the group(s) appear.
And too you can see this video for Contact Form 7 Conditional Fields Tutorial
https://www.youtube.com/watch?v=1AQEmecb0l4