• Resolved StevenP94

    (@stevenp94)


    Hello,
    I’m in trouble with the wp gdpr compliance plugin that add a checkbox to CF7 forms to ensure privacy compliance.
    This checkbox should be required, but I received some mails from forms that reports this control unchecked.

    After a lot of investigations, I replicated the problem on a test site and with custom written plugin code to make tests.

    In few words, if all the controls are shown all work as expected, but if I hide a group the $result->invalidate($tag, $message) is ignored.

    In addition all the internal validation works, only the custom one is ignored.

    Please help me: the forms without privacy acceptance are a big problem!

Viewing 8 replies - 16 through 23 (of 23 total)
  • Thread Starter StevenP94

    (@stevenp94)

    Hi, it works because I used a required field to un-hide the group so to complete required data you automatically unhide the group and all works as expected.

    removing the required flag from the email field, you will notice that the email is sent without checking the checkbox and no error message is given, try this new form:

    https://conditional-fields-cf7.bdwm.be/form-tester/?hash=0f21bdf71bd1109f782f2c1a9beb7463

    if you put data in the Il tuo Nome and Oggetto you will notice that the checkbox is not taken in account

    • This reply was modified 2 years, 6 months ago by StevenP94.
    Plugin Author Jules Colle

    (@jules-colle)

    Ok, I was able to reproduce the error. I’m currently on vacation, but I will look into it when I’m back.

    Thread Starter StevenP94

    (@stevenp94)

    @jules-colle Thanks for all your work, have a nice vacation!

    Plugin Author Jules Colle

    (@jules-colle)

    The reason this isn’t working seems to be because at some point my plugin is calling the WPCF7_Validation->invalidate() function. ( /wp-content/plugins/contact-form-7/includes/validation.php line 15 )

    However, the invalidate function seems to only work for tags that contain a name.

    A quick way to fix this is to also name your custom tag, for example: [wpgdprc wpgdprc], note that for this to work you would also need to declare name-attribute support while adding the form tag in your plugin (line 20):

    wpcf7_add_form_tag( getFieldTag(), 'addFormTagHandler', [ 'name-attr' => true ] );

    You can see this working here: https://conditional-fields-cf7.bdwm.be/form-tester/?hash=388d2d8a5d8634c1dfa72e409a08008f

    I’ll have to study the contact form 7 code a bit further in order to figure out if I should support validation of unnamed form tags.
    There are some major changes coming up in version 5.6 https://contactform7.com/2022/05/20/contact-form-7-56-beta/#introduction-of-schema-woven-validation, so I will be working on compatibility with the newer version, taking into account what I learned in this thread.

    Thread Starter StevenP94

    (@stevenp94)

    Hi, thanks for your reply. At this moment I can’t use your solution because my plugin was written just to test this issue and I can’t modify the wp-gdpr-compliance plugin that suffers of this problem.
    I hope that further changes in upcoming version will solve this problem. I’m still diving in code triying to figure what is the problem and how to solve it.
    I’ll write here if I’ll found something.
    Thanks for now

    Thread Starter StevenP94

    (@stevenp94)

    I found a patch: inside ‘skip_validation_for_hidden_fields’ instead of passing the field name to new validation, the corresponding element of $tags should be passed.
    I’m not so skilled in php so this is a rough soultion, probably cen be better implemented

    foreach ($invalid_fields as $invalid_field_key => $invalid_field_data) {
                    if (!in_array($invalid_field_key, $this->hidden_fields)) {
                        foreach ($tags as $tag) {
                            if ($tag['name'] === $invalid_field_key) {
                               $return_result->invalidate($tag, $invalid_field_data['reason']);
                            }
                        }
                    }
                }

    but in this way all works as it should

    Plugin Author Jules Colle

    (@jules-colle)

    Hi @stevenp94 I think you aced it! Doesn’t seem to interfere in anyway with my tests, and indeed it seems more correct to pass the full tag instead of just the name. Great job! Will do some more tests, and if they all pass I will make sure that this change is added in the next version.

    Thread Starter StevenP94

    (@stevenp94)

    Great!
    Just hope that there is a better way than the foreach to get the correct tag, I’m not so usual to work in php.
    I’m really happy that this solve the problem.

    Thanks for your work on this amazing plugin!

Viewing 8 replies - 16 through 23 (of 23 total)
  • The topic ‘Custom fields validation doesn’t work if a group is hidden’ is closed to new replies.