Support » Plugin: MC4WP: Mailchimp for WordPress » Make checkbox required in Contact Form 7

  • Resolved chever

    (@chever)


    Hello. Is there any way to make [mc4wp_checkbox] as s required field and if it is not checked it will be a typical contact form 7 error validation?
    I want it because I want to use exactly form only for subscribing to mailchimp.
    I have tried [mc4wp_checkbox*] and it is not working – destroying shortcode.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hello,

    To make the CF7 checkbox as a required field, please add the following code to the “functions.php” file located inside your active theme folder.

    /**
     * By default, Contact Form 7 disables HTML5 validation so we can not use the default <code>required</code> attribute.
     *
     * This code uses CF7 logic to ensure that the subscribe checkbox is checked.
     */
    add_filter( 'wpcf7_acceptance', function( $yes ) {
    	if( ! $yes ) { return false; }
    	return ! empty( $_POST['_mc4wp_subscribe_contact-form-7'] );
    });

    I hope that answers your query. Let us know if you have any further questions.

    Thread Starter chever

    (@chever)

    Great, it is working so. Thank you very much!

    Thread Starter chever

    (@chever)

    Update: with this code in functions.php I see that I have error with acceptance in simple CF7 forms that are not used for subscribing, but only for user’s feedbacks. So how to make this your code working only when in CF7 is [mc4wp_checkbox] shortcode?

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hello,

    Can you please share a link to the 2 pages where a CF7 form is used with our shortcode as well as a CF7 form without our checkbox/shortcode?

    Thread Starter chever

    (@chever)

    Hello,

    https://bit.ly/2DCVsMh – this is where CF7 form in the right columb is used for subscribing, so it is with your shortcode and it is working.

    https://bit.ly/2OIIBsX – this is 404 page and there is simple CF7 form with simple cf7 acceptance checkbox but I understand that it wants the [mc4wp_checkbox] shortcode to be checked… Because of code in function.php
    If I remove acceptance field here https://bit.ly/2OIIBsX I have the same error about accept something…
    Also tried with add this line to the Additional Settings section:
    acceptance_as_validation: on
    No result.
    Help me plesase)

    Thread Starter chever

    (@chever)

    Can you help? Please

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hello,

    Please note that 2 links you shared are not accessible. A pop-up login box is displayed. Have you setup Htaccess based security?

    Thread Starter chever

    (@chever)

    Yes sorry, I forgot for this)
    Topic can be closed, because I have fixed it. I have stopped using shorctode in cf7, i just using mailchimp form separatly from cf7 forms.

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hey,

    Thanks for the update.

    gearu

    (@gearu)

    I’ve used the function you’ve provided as well – which works great. However, how do I stop it applying to ALL contact form’s? I only want it to apply to my newsletter subscription, but not to my contact form?

    I’m happy to hard code the ID into the function so it only applies to a specific form – I’m just not sure how to do this (or if there is a better way?)

    • This reply was modified 2 years ago by gearu.

    Hello,

    This is exactly my problem too. What is the fix for this issue?

    Thank you

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Make checkbox required in Contact Form 7’ is closed to new replies.