Support » Plugin: MC4WP: Mailchimp for WordPress » How to add hidden field to comment form

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

    (@hchouhan)

    Hey Carole,

    Thanks for reaching out to us.

    You can change any field to a hidden field by changing the value of “Type” field to “hidden”.

    For e.g. the following field is a checkbox.

    <input type="checkbox" name="_mc4wp_lists[]" value="ListIDgoeshere" />

    This can be made to a hidden field by changing the type property.

    <input type="hidden" name="_mc4wp_lists[]" value="ListIDgoeshere" />

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

    Thread Starter carolemagouirk

    (@carolemagouirk)

    I guess I should have been more specific. 🙂

    I’d like to add a hidden field for a custom field called “SIGNUP” to the comments section on my site using your comment form integration.

    However, I don’t know how to tell your plugin how to do that.

    I’ve I tried adding a custom sign-up form in functions.php:

    function output_hidden_field_in_comment_form() {
      ?>
        <label>
          <input type="checkbox" name="mc4wp-subscribe" value="1" />
          Subscribe to my newsletter.
        </label>
        <input type="hidden" name="mc4wp-SIGNUP" value="Comments">
      <?php
    }
    add_action( 'comment_form', 'output_hidden_field_in_comment_form' );

    I’ve tried SIGNUP and mc4wp-SIGNUP as the name to my hidden form.

    Is there some version of _mc4wp_lists[] I should be using?

    Thread Starter carolemagouirk

    (@carolemagouirk)

    Here’s I got it working. I added the following code to functions.php:

    // Add signup location to comments subscribe checkbox
    add_filter( 'comment_form_field_email', 'my_comment_form_field_email' );
    function my_comment_form_field_email( $email_field ) {
        return $email_field.'<label><input type="checkbox" name="mc4wp-subscribe" value="1" />Subscribe to my newsletter.</label><input type="hidden" name="mc4wp-SIGNUP" value="Comments">';
    }

    This looks for the email field, adds the checkbox below it, and correctly attributes my hidden field in mailchimp.

    I found this solution based on this answer in stackexchange: https://wordpress.stackexchange.com/a/127030

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to add hidden field to comment form’ is closed to new replies.