cosmoloc
cosmoloc

Reputation: 3004

Contact Form 7 : send default value to mail if textarea empty

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

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

And Mail Format is :

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

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 ?

Upvotes: 4

Views: 10213

Answers (5)

Vasco
Vasco

Reputation: 17

I tried the code provided by @DACrosby above, but that one didn't work for me. So I deleted some code and changed it to this, and then it works perfectly!

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;
}

Upvotes: 0

DACrosby
DACrosby

Reputation: 11460

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.

Upvotes: 5

bv.ebizzinfotech
bv.ebizzinfotech

Reputation: 62

It's so eassy.
Select Textarea option from generate tag dropdown menu in contactform form generation.
And there is option for set default value.
By using that option you can set default value of textarea. I Have attached one image here...
In that image i shown details.

ContactForm7 Add new form

Its work for me...
I hope that it's also work for you.

Upvotes: 0

danyo
danyo

Reputation: 5856

According to the Contact Form 7 Website you can specify default values.

Example:

[email* your-email default:user_email]

This will populate the field with the current users email address.

more information here

Upvotes: 0

Tom
Tom

Reputation: 139

You can't do that with Contact Form 7 as far as I know.

Upvotes: -2

Related Questions