[bugfix] skip_validation_for_hidden_fields issue
-
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)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘[bugfix] skip_validation_for_hidden_fields issue’ is closed to new replies.