A
A
ak_wi2018-06-10 13:33:20
WordPress
ak_wi, 2018-06-10 13:33:20

How to change the letter through hook for Contact Form 7?

I'm using this hook right now:

add_filter( 'wpcf7_validate_textarea', 'custom_textarea_validation_filter', 20, 2 );
add_filter( 'wpcf7_validate_textarea*', 'custom_textarea_validation_filter', 20, 2 );
 
function custom_textarea_validation_filter( $result, $tag ) {
    if ( 'your-message' == $tag->name ) {
        $your_message = isset( $_POST['your-message'] ) ? trim( $_POST['your-message'] ) : '';
 
        if ( strpos($your_message, 'http://') !== false ) {
            $result->invalidate( $tag, "Incorrect value" );
        }
    }
 
    return $result;
}

It is necessary to replace
$result->invalidate( $tag, "Incorrect value" );
With some hook that would change the body of the letter that Contact Form 7 sends to the user. That is, if the condition is true, then the user receives a letter with text A, and if not, a standard letter with text B, which is set from the admin panel.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Yanchevsky, 2018-06-10
@deniscopro

I'm using this hook right now:

This hook checks the form data and determines if the form is submitted or not.
You can try to change the message, for example, like this:
add_filter('wpcf7_posted_data', 'my_wpcf7_posted_data');

function my_wpcf7_posted_data($posted_data) {
    if (isset($posted_data['your-message']) && strpos($posted_data['your-message'], 'http://') !== false) {
        $posted_data['your-message'] = 'Мой текст';
    }

    return $posted_data;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question