• Resolved dedotombo

    (@dedotombo)


    Hi,

    I have been experiencing an incompatibility between this plugin and the WP GDPR Compliance plugin: when CF7 conditional fields were enabled, the GDPR field stopped validating. Instead of being mandatory, users could proceed without accepting the checkbox.

    After debugging with error_log I found out that the skip_validation_for_hidden_fields has a bug, it calls the invalidate method of the WPCF7_Validation object in a wrong way.

    Here is my proposed fix, it seems to work. Instead of passing a string as the first argument of the invalidate method, I pass the corresponding WPCF7_FormTag object.

    function skip_validation_for_hidden_fields($result, $tags, $args = []) {
    
            if(isset($_POST)) {
                $this->set_hidden_fields_arrays($_POST);
            }
    
            $invalid_fields = $result->get_invalid_fields();
            $return_result = new WPCF7_Validation();
    		
    
            if (count($this->hidden_fields) == 0 || !is_array($invalid_fields) || count($invalid_fields) == 0) {
                $return_result = $result;
            } else {
                foreach ($invalid_fields as $invalid_field_key => $invalid_field_data) {
                    if (!in_array($invalid_field_key, $this->hidden_fields)) {
                        // the invalid field is not a hidden field, so we'll add it to the final validation result
    					foreach ($tags as $tag) {
    						if ($tag->name == $invalid_field_key) {
    							$return_result->invalidate($tag, $invalid_field_data['reason']);
    						}
    					}
                    }
                }
            }
    
            return apply_filters('wpcf7cf_validate', $return_result, $tags);
    
        }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jules Colle

    (@jules-colle)

    Hi dedotombo, thanks for reporting! I checked, and your proposed change seems to logically boil down to more or less the same thing. The invalidate function will try and parse a string to a $tag anyway, so I went ahead and implemented this change because it seems to make sense and all my automated tests still pass.

    Will release version 2.0.2 with the change shortly.

    Plugin Author Jules Colle

    (@jules-colle)

    should be fixed

    Thread Starter dedotombo

    (@dedotombo)

    Thank you Jules, much appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[bugfix] skip_validation_for_hidden_fields issue’ is closed to new replies.