【问题标题】:Add a custom field to Contact Form 7 tag将自定义字段添加到联系表 7 标记
【发布时间】:2015-12-31 03:25:51
【问题描述】:

我想将自定义字段添加到 cf7 标记。 (见图) 我可以使用任何 add_filter 钩子吗? 请帮帮我。

谢谢

【问题讨论】:

  • 你能详细说明这个标签应该是什么吗?有些标签没有很好的记录,如果没有 - 我知道这样做的一些方法,但这将取决于自定义字段本身..
  • 您好 Obmerk Kronen,感谢您的回复。我想在每个标签中插入一个文本字段以将值传递给简码。谢谢
  • 是的,我明白 - 但价值是什么?如上所述,一些 CF7 标签已经存在(尽管文档很差)并且不需要特殊的钩子.. 像 sender IPpost_IDsent_timeunique_id 以及实际上许多其他标签......
  • 我需要一个文本字段,用户可以在其中插入文本,并且此值在短代码中作为数据属性。例如,我在我的自定义字段“Hello”中插入值,当我呈现的简码时,我可以看到 [code][code]
  • 好的,我以前做过,让我从repos中挖一些代码..

标签: wordpress contact-form-7


【解决方案1】:

好吧,我可能误解了你想要什么,但是:

这是 CF7 注册文本字段短标签的方式:

add_action( 'wpcf7_init', 'wpcf7_add_shortcode_text' );

function wpcf7_add_shortcode_text() {
    wpcf7_add_shortcode(
        array( 'text', 'text*', 'email', 'email*', 'url', 'url*', 'tel', 'tel*' ),
        'wpcf7_text_shortcode_handler', true );
}

请注意,函数 wpcf7_add_shortcode() 的钩子是 wpcf7_init 所以,如果我们自己做例子:

add_action( 'wpcf7_init', 'custom_add_shortcode_hello' );



function custom_add_shortcode_hello() {
    wpcf7_add_shortcode( 'helloworld', 'custom_hello_shortcode_handler' ); // "helloworld" is the type of the form-tag
}

然后是回调处理程序

function custom_hello_shortcode_handler( $tag ) {
    return 'hello world ! ';
}

现在,如果您将其添加到表单中

CF7 say : [helloworld]

你应该看到

CF7 say : hello world ! 

如果你想使用普通的表单标签,请注意可用的默认类型是:

text, text*, email, email*, tel, tel*, url, url*, textarea ,textarea* , number, number*, range and range* , date , date*,checkbox, checkbox*, radio, select and select* , file , file*, captchac ,captchar, quiz , acceptance, submit;

现在,我写了所有这些,因为据我所知(而且我可能错了)对于在函数 wpcf7_tg_pane_text_and_relatives() in modules/text.php 中定义的现有标签的 HTML 表单没有过滤器/p>

,但是您可以做的是使用 wpcf7_remove_shortcode( $tag ); 删除默认标签(例如 text ),然后通过创建一个新标签(例如 text )添加您自己的适应上面的示例以适应您的需要

话虽如此,我还不确定你想要什么以及为什么想要这个(你真的没有解释目标,只是方式)因为恕我直言,并且在我编写了很多 CF7 自定义插件之后,我真的想要不明白为什么不直接创建一个新标签,这样更容易构建。

但话说回来,我可能错了。

【讨论】:

  • 赞成,因为这个答案包含一些有用的信息,而且 OP 的原始问题非常模糊......
  • @fazen 我找不到插件,能否提供下载该插件的链接?
  • wpcf7_add_shortcode() 已弃用,其替代方法是:wpcf7_add_form_tag() contactform7.com/2016/12/03/contact-form-7-46
猜你喜欢
  • 2014-09-24
  • 2017-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-29
  • 2018-05-05
  • 2013-12-28
相关资源
最近更新 更多