Title: Custom Errors Filter not working
Last modified: October 15, 2024

---

# Custom Errors Filter not working

 *  Resolved [danidada](https://wordpress.org/support/users/danidada/)
 * (@danidada)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/custom-errors-filter-not-working/)
 * I have a problem with a filter: I created a mu-plugin with this code to validate
   a field hidden by css that must remain empty (as an antibot field):
 *     ```wp-block-code
       add_filter( 'forminator_custom_form_submit_errors', 'check_form_data', 99, 3 );function check_form_data( $submit_errors, $form_id, $field_data_array ) {    $valid = false;    $antibotFieldName = "";    foreach( $field_data_array as $val ) {        if( $val['placeholder'] == 'antibot' ) {            $antibotVal = $val['value'];            $antibotFieldName = $val['name'];            if($antibotVal == ""){                $valid = true;            }            break;        }    }    if( ! $valid ) {        $submit_errors[][$antibotFieldName] = 'Antibot verifica fallita!';    }    return $submit_errors;}
       ```
   
 * but I can’t make it work, it’s ignored..am I missing something?
 * Thanks

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

 *  Plugin Support [Saurabh – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support7/)
 * (@wpmudev-support7)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/custom-errors-filter-not-working/#post-18075746)
 * Hello [@danidada](https://wordpress.org/support/users/danidada/)
 * Hope you’re doing well today!
 * The error action hook that you are using seems correct, however, I am afraid 
   reviewing and working on the action code will be out of support scope. For that,
   you’ll need to hire a developer to provide the required custom code for you.
 * WordPress provides a jobs directory here [https://jobs.wordpress.net/](https://jobs.wordpress.net/)
 * That said, looking at what you are trying to achieve, we have a similar “native”
   feature within Forminator Form Plugin known as “HoneyPot Protection” Have you
   already tried that?
 * Ref: [https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#enable-honeypot-protection](https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#enable-honeypot-protection)
 * You can enable it by navigating to the **Form >> Behaviour >> Security >> Enable
   HoneyPot Protection**.
 * Kind Regards,
    Saurabh
 *  Thread Starter [danidada](https://wordpress.org/support/users/danidada/)
 * (@danidada)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/custom-errors-filter-not-working/#post-18075765)
 * thanks for your reply.
 * yes honeypot is turned on and hcaptcha is also integrated in the form but there’s
   still spam.
 * I can code so can you confirm how the filter works? Does it apply only to require
   fields? There’s another filter or hook I can use to add a custom validation for
   field? The form is submitted with ajax.
 * thanks again
 *  [Kris – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport13/)
 * (@wpmudevsupport13)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/custom-errors-filter-not-working/#post-18081060)
 * Hi [@danidada](https://wordpress.org/support/users/danidada/)
 * I pinged our SLS Team to review your query. We will post an update here as soon
   as more information is available.
 * Kind Regards,
   Kris
 *  Thread Starter [danidada](https://wordpress.org/support/users/danidada/)
 * (@danidada)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/custom-errors-filter-not-working/#post-18081321)
 * thank you, I’ll wait for them.
 *  Plugin Support [Patrick – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport12/)
 * (@wpmudevsupport12)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/custom-errors-filter-not-working/#post-18083778)
 * Hi [@danidada](https://wordpress.org/support/users/danidada/)
 * On your code there are some errors in how you use the $field_data_array, you 
   can always check it by using
 * `error_log( print_r( $field_data_array, true ) );`
 * Then check the debug.log file ( note you need to have the debug mode enabled )
 * The field placeholder is inside of “field_array” key and $field_data_array is
   an array of each field so you need to target that key to reach the placehoder.
 * An example of structure:
 *     ```
       (
           [0] => Array
               (
                   [name] => name-1
                   [value] => 
                   [field_type] => name
                   [key] => 1
                   [field_array] => Array
                       (
                           [element_id] => name-1
                           [type] => name
                           [options] => Array
                               (
                               )
   
                           [cols] => 12
                           [conditions] => Array
                               (
                               )
   
                           [wrapper_id] => wrapper-2752-2028
                           [field_label] => Name
                           [placeholder] => E.g. John Doe
                           [prefix_label] => Prefix
                           [fname_label] => First Name
                           [fname_placeholder] => E.g. John
                           [mname_label] => Middle Name
                           [mname_placeholder] => E.g. Smith
                           [lname_label] => Last Name
                           [lname_placeholder] => E.g. Doe
                           [prefix] => true
                           [fname] => true
                           [mname] => true
                           [lname] => true
                           [required_message] => Name is required.
                           [prefix_required_message] => Prefix is required.
                           [fname_required_message] => First Name is required.
                           [mname_required_message] => Middle Name is required.
                           [lname_required_message] => Last Name is required.
                           [layout_columns] => 2
                           [parent_group] => 
                       )
   
                   [form_field_obj] => Forminator_Name Object
                       (
                           [field] => Array
                               (
                               )
   
                           [form_settings] => Array
                               (
                               )
   
                           [name] => Name
                           [slug] => name
                           [category] => standard
                           [type] => name
                           [options] => Array
                               (
                               )
   
                           [settings] => Array
                               (
                               )
   
                           [autofill_settings] => Array
                               (
                                   [name] => Array
                                       (
                                           [values] => Array
                                               (
                                                   [wp_user] => Array
                                                       (
                                                           [name] => WordPress User
                                                           [attributes] => Array
                                                               (
                                                                   [wp_user.display_name] => Array
                                                                       (
                                                                           [name] => Display Name
                                                                       )
   
                                                                   [wp_user.login] => Array
                                                                       (
                                                                           [name] => Username
                                                                       )
   
                                                                   [wp_user.first_name] => Array
                                                                       (
                                                                           [name] => First Name
                                                                       )
   
                                                                   [wp_user.last_name] => Array
                                                                       (
                                                                           [name] => Last Name
                                                                       )
   
                                                               )
   
                                                       )
   
                                               )
   
                                       )
   
                                   [name-prefix] => Array
                                       (
                                           [values] => Array
                                               (
                                               )
   
                                       )
   
                                   [name-first-name] => Array
                                       (
                                           [values] => Array
                                               (
                                                   [wp_user] => Array
                                                       (
                                                           [name] => WordPress User
                                                           [attributes] => Array
                                                               (
                                                                   [wp_user.first_name] => Array
                                                                       (
                                                                           [name] => First Name
                                                                       )
   
                                                                   [wp_user.display_name] => Array
                                                                       (
                                                                           [name] => Display Name
                                                                       )
   
                                                                   [wp_user.login] => Array
                                                                       (
                                                                           [name] => Username
                                                                       )
   
                                                               )
   
                                                       )
   
                                               )
   
                                       )
   
                                   [name-middle-name] => Array
                                       (
                                           [values] => Array
                                               (
                                               )
   
                                       )
   
                                   [name-last-name] => Array
                                       (
                                           [values] => Array
                                               (
                                                   [wp_user] => Array
                                                       (
                                                           [name] => WordPress User
                                                           [attributes] => Array
                                                               (
                                                                   [wp_user.last_name] => Array
                                                                       (
                                                                           [name] => Last Name
                                                                       )
   
                                                                   [wp_user.login] => Array
                                                                       (
                                                                           [name] => Username
                                                                       )
   
                                                               )
   
                                                       )
   
                                               )
   
                                       )
   
                               )
   
                           [defaults] => Array
                               (
                                   [field_label] => Name
                                   [placeholder] => E.g. John Doe
                                   [prefix_label] => Prefix
                                   [fname_label] => First Name
                                   [fname_placeholder] => E.g. John
                                   [mname_label] => Middle Name
                                   [mname_placeholder] => E.g. Smith
                                   [lname_label] => Last Name
                                   [lname_placeholder] => E.g. Doe
                                   [prefix] => true
                                   [fname] => true
                                   [mname] => true
                                   [lname] => true
                                   [required_message] => Name is required.
                                   [prefix_required_message] => Prefix is required.
                                   [fname_required_message] => First Name is required.
                                   [mname_required_message] => Middle Name is required.
                                   [lname_required_message] => Last Name is required.
                                   [layout_columns] => 2
                               )
   
                           [hide_advanced] => 
                           [position] => 1
                           [is_input] => 
                           [has_counter] => 
                           [is_valid] => 1
                           [validation_message] => Array
                               (
                               )
   
                           [activated_autofill_providers:protected] => Array
                               (
                               )
   
                           [icon] => sui-icon-profile-male
                           [is_calculable] => 
                       )
   
               )
   
       )
       ```
   
 * But it is easier if you target the field name instead, e.g text-1 then you can
   the $val[‘name’] == ‘something’ without field_array key.
 * Note, that this is just a small guide we can’t provide the final code as it is
   outside our support scope.
 * But to fight spam is better to think about website security in general example
   using Cloudflare, blocking some countries if you provide support to a specific
   country audience only.
 * You can find more [https://wpmudev.com/blog/prevent-form-comment-spam-forminator/](https://wpmudev.com/blog/prevent-form-comment-spam-forminator/)
 * Best Regards
    Patrick Freitas
 *  Thread Starter [danidada](https://wordpress.org/support/users/danidada/)
 * (@danidada)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/custom-errors-filter-not-working/#post-18088013)
 * Sorry for the late reply.
 * Based on your suggestion I edited the code with:
   `if( $val['field_array']['placeholder']
   == 'antibot' ) {`and it didn’t work, nothing changed.
 * 
   So I added in config.php
 * `define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true );`
   and changed the
   filter to:
 * add_filter( ‘forminator_custom_form_submit_errors’, ‘check_form_data’, 99, 3 );
   
   function check_form_data( $submit_errors, $form_id, $field_data_array ) {    
   error_log( print_r( $field_data_array, true ) );    return $submit_errors;}
 * but testing the form I see the validations error (leaving all fields blank) but
   no debug.log into wp-content folder. So my guess is that the filter is not firing.
   
   It’s an ajax form if I missed to say that before. The filter is added in a mu-
   plugin visible from wp backend.
 *  [Kris – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport13/)
 * (@wpmudevsupport13)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/custom-errors-filter-not-working/#post-18093219)
 * Hi [@danidada](https://wordpress.org/support/users/danidada/)
 * We are checking your data with our SLS Team. Thank you for your patience while
   we look into this further.
 * Kind Regards,
   Kris
 *  [Kris – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport13/)
 * (@wpmudevsupport13)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/custom-errors-filter-not-working/#post-18094253)
 * Hi again [@danidada](https://wordpress.org/support/users/danidada/)
 * We have some update from SLS team and that filter should be in the loop. Some
   example:
 *     ```wp-block-code
       add_filter(	'forminator_custom_form_submit_errors',	function(  $submit_errors, $form_id, $field_data_array ) {		foreach ( $field_data_array as $field ) {			$placeholder = ! empty( $field['field_array']['placeholder'] ) ? $field['field_array']['placeholder'] : '';			. 			. 			.		}		return $submit_errors;	},	10,	3);
       ```
   
 * Kind Regards,
   Kris
 *  Plugin Support [Nithin – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport11/)
 * (@wpmudevsupport11)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/custom-errors-filter-not-working/#post-18109020)
 * Hi [@danidada](https://wordpress.org/support/users/danidada/),
 * Since we haven’t heard from you for a while. I’ll mark this thread as resolved
   for now. Please feel free to re-open this thread if you need any further assistance.
 * Best Regards
   Nithin

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

The topic ‘Custom Errors Filter not working’ is closed to new replies.

 * ![](https://ps.w.org/forminator/assets/icon-256x256.gif?rev=3443182)
 * [Forminator Forms – Contact Form, Payment Form & Custom Form Builder](https://wordpress.org/plugins/forminator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/forminator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/forminator/)
 * [Active Topics](https://wordpress.org/support/plugin/forminator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/forminator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/forminator/reviews/)

## Tags

 * [errors](https://wordpress.org/support/topic-tag/errors/)
 * [filter](https://wordpress.org/support/topic-tag/filter/)
 * [submit](https://wordpress.org/support/topic-tag/submit/)

 * 9 replies
 * 5 participants
 * Last reply from: [Nithin – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport11/)
 * Last activity: [1 year, 6 months ago](https://wordpress.org/support/topic/custom-errors-filter-not-working/#post-18109020)
 * Status: resolved