联系表格7:如果textarea为空,则将默认值发送给邮件 [英] Contact Form 7 : send default value to mail if textarea empty

查看:70
本文介绍了联系表格7:如果textarea为空,则将默认值发送给邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[您的名字]我有一个联系表单7 3.7,其中的textarea字段为:

[your-name] I have a contact form7 3.7 with a textarea field as :

<p>Message (optional)<br />
[textarea my-message]</p>

邮件格式为:

From :    [your-name] | [your-email]
Message : [my-message]

现在,当前为文本区域为空。

如果用户未在消息框中填充任何数据,则邮件发送时带有空字段。

如果textarea默认如何发送无值是空的吗?

Now, currently the textarea is empty.
if user does not fills any data in message box, the mail is sent with empty field.
How to send "None" value by default if the textarea is empty ?

推荐答案

这花了一段时间才找到,可以使用,但可以在<$ c $中尝试c> functions.php 文件:

This took a while to find and could use some work yet, but try this in your functions.php file:

add_action("wpcf7_posted_data", "wpcf7_modify_this");
function wpcf7_modify_this($posted_data) {

    // if user leaves the message area blank, set to "None"
    if ($posted_data['my-message'] == "")
        $posted_data['my-message'] = "None";

    // generic example
    if ( /* some logic */ )
        $posted_data['/* cf7-field-name */'] = "ValueToEmail";

    return $posted_data;
}

这里要注意的一件事是验证发生在此之前,因此如果您允许用户输入一个空白值,而不是必需的。

One thing to note here is that validation occurs prior to this point, so if you're allowing users to enter a blank value, don't make it required.

这篇关于联系表格7:如果textarea为空,则将默认值发送给邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆