Support » Plugin: Contact Form 7 Multi-Step Forms » Conflicts with CF7 Conditional Fields plugin in PHP 8.0

  • Resolved fijisunshine

    (@fijisunshine)


    Great plugin!

    I believe this plugin conflicts with the “Contact Form 7 – Conditional Fields” plugin when using PHP 8.0. If this plugin, or that plugin, is disabled then the issue is gone. The plugins do not conflict in PHP 7.4.

    I’m running WordPress 5.7 and CF7 version 5.3.2.

    Any suggestions? Thank you

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author webheadcoder

    (@webheadllc)

    Hi,

    Thank you for letting me know. It looks like PHP 8 is a bit more sensitive with the array errors. If you want to fix it immediately, I think you can try changing lines 193 – 195 in cf7cf.php from:

    $cookie_data_hidden_group_fields = json_decode(stripslashes($cookie_data['_wpcf7cf_hidden_group_fields']));
    $cookie_data_hidden_groups = json_decode(stripslashes($cookie_data['_wpcf7cf_hidden_groups']));
    $cookie_data_visible_groups = json_decode(stripslashes($cookie_data['_wpcf7cf_visible_groups']));

    To:

    $cookie_data_hidden_group_fields = json_decode(stripslashes(isset($cookie_data['_wpcf7cf_hidden_group_fields']) ? $cookie_data['_wpcf7cf_visible_groups'] : ''));
    $cookie_data_hidden_groups = json_decode(stripslashes(isset($cookie_data['_wpcf7cf_hidden_groups']) ? $cookie_data['_wpcf7cf_visible_groups'] : ''));
    $cookie_data_visible_groups = json_decode(stripslashes(isset($cookie_data['_wpcf7cf_visible_groups']) ? $cookie_data['_wpcf7cf_visible_groups'] : ''));

    This should make it compatible for PHP 8 and also < 7.

    @jules-colle If you have time to take a look at this that would be great. Thank you for making our plugins compatible!

    • This reply was modified 1 month, 3 weeks ago by webheadcoder. Reason: spacing issues
    Thread Starter fijisunshine

    (@fijisunshine)

    Thank you for your excellent response.

    Just to be sure, did you intend to use “_wpcf7cf_visible_groups” in all 3 lines of code? That doesn’t seem right to me. Can you confirm that it is?

    Thanks again

    Plugin Author webheadcoder

    (@webheadllc)

    Oh very sorry about that. Thank you or catching that. Each line should be different. here is the corrected code:

    $cookie_data_hidden_group_fields = json_decode(stripslashes(isset($cookie_data['_wpcf7cf_hidden_group_fields']) ? $cookie_data['_wpcf7cf_hidden_group_fields'] : ''));
    $cookie_data_hidden_groups = json_decode(stripslashes(isset($cookie_data['_wpcf7cf_hidden_groups']) ? $cookie_data['_wpcf7cf_hidden_groups'] : ''));
    $cookie_data_visible_groups = json_decode(stripslashes(isset($cookie_data['_wpcf7cf_visible_groups']) ? $cookie_data['_wpcf7cf_visible_groups'] : ''));
    Thread Starter fijisunshine

    (@fijisunshine)

    Ok, thank you for confirming.

    I think the plugins are still conflicting in php 8. My contact form won’t show any messages, i.e. validation errors, submission confirmation, etc.

    No errors in the log. In the browser console, I get this error when trying to submit any CF7 form:

    “Failed to load resource: the server responded with a status of 500 ()

    …/contact-form-7/v1/contact-forms/123456/feedback:1”

    This console error disappears in php 7.4. It also disappears if I disable either plugin when using php 8.

    Any suggestions? Thanks again

    Plugin Author webheadcoder

    (@webheadllc)

    That’s strange it worked earlier. I must’ve changed something while testing it. Please try this code. It is slightly different from previous versions.

    Just wanted to mention again, this is an unofficial fix and the developer of the Conditional Fields plugin will need to fix this before the next update. Otherwise this fix will be erased in your files. He has generously added code to make our plugins compatible. If for some reason he doesn’t add a fix for this I’ll see what I can add to mine.

    $cookie_data_hidden_group_fields = json_decode(stripslashes(isset($cookie_data['_wpcf7cf_hidden_group_fields']) ? $cookie_data['_wpcf7cf_visible_groups'] : '[]'));
    $cookie_data_hidden_groups = json_decode(stripslashes(isset($cookie_data['_wpcf7cf_hidden_groups']) ? $cookie_data['_wpcf7cf_visible_groups'] : '[]'));
    $cookie_data_visible_groups = json_decode(stripslashes(isset($cookie_data['_wpcf7cf_visible_groups']) ? $cookie_data['_wpcf7cf_visible_groups'] : '[]'));
    Thread Starter fijisunshine

    (@fijisunshine)

    Excellent, thank you very much for fixing the issue. With your newest code, the conflict in php 8.0 appears to be gone. CF7 forms are showing messages again.

    Yes, I understand that this temporary fix will be overridden when I update the Conditional Fields plugin. Thanks for the reminder.

    Thread Starter fijisunshine

    (@fijisunshine)

    Thanks again for your response. Just to confirm: In your newest code above, did you mean to use “_wpcf7cf_visible_groups” in all 3 lines? In your 2nd newest code above, you didn’t do that.

    Can you confirm if “_wpcf7cf_visible_groups” should be in all 3 lines? Thanks again

    Plugin Author webheadcoder

    (@webheadllc)

    oh geez. I did it again. no, _wpcf7cf_visible_groups should not be on all 3 lines. I’m not going to attempt to paste the code again…. Each line should be a different cookie_data key.

    Does that affect your form? When I was testing it, I didn’t notice anything off. I did only have a very simple form though.

    Thread Starter fijisunshine

    (@fijisunshine)

    Thanks again for your response. In the latest version of the plugins, the issue appears to be fixed. Your temporary fix was greatly appreciated but it doesn’t appear to be needed when using the latest version of the plugins.

    Thanks again

    Thread Starter fijisunshine

    (@fijisunshine)

    Sorry, I spoke too soon. The issue is resolved but only when using your suggested code in cf7cf.php near line 206:

    $cookie_data_hidden_group_fields = json_decode(stripslashes(isset($cookie_data['_wpcf7cf_hidden_group_fields']) ? $cookie_data['_wpcf7cf_hidden_group_fields'] : '[]'));
    		$cookie_data_hidden_groups = json_decode(stripslashes(isset($cookie_data['_wpcf7cf_hidden_groups']) ? $cookie_data['_wpcf7cf_hidden_groups'] : '[]'));
    		$cookie_data_visible_groups = json_decode(stripslashes(isset($cookie_data['_wpcf7cf_visible_groups']) ? $cookie_data['_wpcf7cf_visible_groups'] : '[]'));

    @jules-colle can use this code as a guide for a future update regarding PHP 8.0

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.