Search code examples
wordpresscontact-form-7

Changing Contact Form 7 alert message after submit based on input value


Does anyone know how to change cf7 alert message when the input value is greater than 10?

If input value = 11 or up change the cf 7 alert message after submitting it.

enter image description here

Thanks for your help.


Solution

  • You could hook into the before_send_mail and update the message based on a specific field.

    add_action ('wpcf7_before_send_mail', 'dd_before_send_mail');
    function dd_before_send_mail($contact_form){
        // Get the instance
        $submission = WPCF7_Submission :: get_instance();
        if ($submission){
            $fields = $submission->get_posted_data();
            // put your field name in for [your-field]
            if (intval($fields['your-field'] ) > 10 ) {
                $contact_form -> set_properties(array('messages' => array('mail_sent_ok' => 'This is your message')));
            }
        }
    }