如何在隐藏输入中发送表单标题(联系表单 7 - WP 插件)?

How, send Form title (Contact form 7 - WP Plugin) in hidden input?

是否可以在电子邮件中发送联系人表单名称body?

[contact-form-7 id="86" title="联系表格 1"]

我尝试使用 Contact Form 7 动态文本扩展 — WordPress 插件,但我的表单位于模态项中,当我单击其中一个时,显示模态,然后更改 url(添加 -> ? id=23) 但动态文本扩展仅在重新加载页面中不接受此字段。

有什么帮助吗?

谢谢

我在 functions.php 中对隐藏输入字段和自定义短代码做了类似的事情。这也可能有帮助

wpcf7_add_shortcode('hidden', 'wpcf7_sourceurl_shortcode_handler', true);

function wpcf7_sourceurl_shortcode_handler($tag) {
    if (!is_array($tag)) return '';

    $name = $tag['name'];
    if (empty($name)) return '';

    $html = '<input type="hidden" name="' . $name . '" value="' . get_the_title() . '" />';
   return $html;
}

然后在联系表 7 中添加自定义标签

[hidden pageTitle]

在电子邮件设置中

Page title is: [pageTitle]

我来晚了(一如既往),但我还需要区分相同形式的实例。通过搜索 Whosebug 和源代码,我想出了一个解决方案:

将此添加到您的 functions.php:

add_action( 'wpcf7_init', 'cf7_add_form_title' );
function cf7_add_form_title() {
    wpcf7_add_form_tag( 'form_title', 'cf7_add_form_title_handler' );
}
function cf7_add_form_title_handler( $tag ) {
    $form = wpcf7_get_current_contact_form();
    return $form->shortcode_attr('title');
}

作为隐藏表单域:

<input type="hidden" name="title" value="[form_title]"/>

作为电子邮件标签:

[title]

名字当然可以是任何名字。

你可以只使用 cf7 插件 features:

在表单模板中添加隐藏字段,例如[hidden title default:shortcode_attr]

然后在邮件正文中使用此字段[title]

适合我。