• Resolved Dirk Tornow

    (@smings)


    I wrote a custom validation like described in here on your website..

    Using the ‘mc4wp_form_errors’ filter works just fine. But when I want to add an error message, the ‘mc4wp_form_message’ filter simply doesn’t fire. I can’t add the error message via the filter. When I add in the MC4WP plugin directly after the
    $messages = (array) apply_filters( 'mc4wp_form_messages', $messages, $form );
    it works just fine.
    I used your exact example code except for that i use it in a class.

    add_filter('mc4wp_form_message', array( $this, 'add_mc4wp_error_message'), 10, 2 );
    .
    .
    .
    public function add_mc4wp_error_message( $message )
    {
     $messages['my_validation_error'] = array( 'type' => 'error', 'text' => 'my validation error test message' );
     return $messages;
    }
    

    When I simply add the same line
    $messages['my_validation_error'] = array( 'type' => 'error', 'text' => 'my validation error test message' );
    right after the apply_filter line (class-form.php lime 276 in your plugin), my error message gets displayed. I can’t figure out, why the filter doesn’t fire and add my error message to the array?
    Could you please nudge me in the right direction or provide a working example?
    Thank you very much in advance for your support.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Dirk Tornow

    (@smings)

    I found the bug. On your validation example page it states

    add_filter('mc4wp_form_message', 'myprefix_add_mc4wp_error_message');
    But it would have to be

    
    add_filter('mc4wp_form_messages', 'myprefix_add_mc4wp_error_message');
                                  ^
    

    After digging into MC4WP’s code I found the difference. Please correct the example code on your website accordingly. I close this ticket.
    Have a great day!

    Plugin Contributor Lap

    (@lapzor)

    Great find!! Thank you for sharing. I will make sure the KB article is updated. It’s been there for a long time and nobody ever noticed.

    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘‘mc4wp_form_message’ filter doesn’t work’ is closed to new replies.