• Resolved VinzClortho

    (@vinzclortho)


    Hello,
    I have different forms for different interest groups. I am using the integration for both the CF7 and the comment module, with the code you provided in your guide.
    In the contact form I added:
    <input name="mc4wp-INTERESTS[number]" value="group" type="hidden" />
    It works, the user is register in the correct group.

    I have a problem in the contact form when I registering custom fields for comment form, with this hook to function.php

    add_action ('comment_form', function() {
    ?>
    <input name="INTERESTS[number]" value="group" type="hidden">
    <? Php
    });
    
    add_filter ('mc4wp_integration_data', function ($ vars) {
    $vars ['INTERESTS'] = isset($ _POST['INTERESTS'])? $_POST['INTERESTS']: array ();
    return $vars;
    });

    With this code, the user is registered in the group from comment form, but no longer works the CF7 integration: from the contact form the user is subscribed to the list, but not to the group.

    How can I use both of these codes together without conflict?

    Thanks

    • This topic was modified 6 years, 1 month ago by VinzClortho.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hello,

    Thanks for reaching out to us.

    Can you please try adding a prefix of “MC4WP-” in front of the name of the hidden field added to comment form?

    Also, can you please try removing the filter code (the one below) and test again?

    add_filter ('mc4wp_integration_data', function ($ vars) {
    $vars ['INTERESTS'] = isset($ _POST['INTERESTS'])? $_POST['INTERESTS']: array ();
    return $vars;
    });
    Thread Starter VinzClortho

    (@vinzclortho)

    Hello,
    Thanks for the reply

    I tried to add the prefix, but if I do not add the filter, when the user is registered in the list is not added to any group (it is also specified in your guide).
    If I add both the prefix and the filter (in the comments), the user is not added to the group either by CF7 or by the comment form.

    Plugin Contributor Lap

    (@lapzor)

    Hi,

    If the field is hidden anyway, you don’t really need the hidden field, you can do it directly in the code like this:

    add_filter( ‘mc4wp_integration_wp-comment-form_data’, function( MC4WP_MailChimp_Subscriber $subscriber ) {
    // replace “interest-id” with the actual ID of your interest.
    $subscriber->interests[ “interest-id” ] = true;
    // repeat for all interests you want to enable or disable
    // $subscriber->interests[ “91lxm10xzl” ] = true;
    // $subscriber->interests[ “91lxm10xzl” ] = false;
    return $subscriber;
    });

    This code will only be applied to the comment form integration because of the integration slug in the filter name: https://github.com/ibericode/mc4wp-snippets/blob/master/integrations/integration-slugs.md

    Hope that helps. If you have any questions, please let us know!

    Thread Starter VinzClortho

    (@vinzclortho)

    Hello,
    in the hidden field is indicated the ID of the interest group (name=”INTERESTS[number]”) and also to which group the user must be registered (value=”group”).
    In your code, how can I indicate the value of the group?

    Thanks

    Thread Starter VinzClortho

    (@vinzclortho)

    Hello,
    I understood that in your code I have to add the ID of each single group. I found them on the Mailchimp Developer Playground. If I understood correctly:

    GET lists/list_id/interest-categories/category_id/interests/id

    category_id > ID of the interest field
    list_id > ID List
    id > ID of the single group

    I then added your code to my function.php in this way:

    add_filter( 'mc4wp_integration_wp-comment-form_data', function( MC4WP_MailChimp_Subscriber $subscriber ) {
    // replace “interest-id” with the actual ID of your interest.
    $subscriber->interests[ 'category_id' ] = true;
    // repeat for all interests you want to enable or disable
    $subscriber->interests[ 'id-group-1' ] = true;
    $subscriber->interests[ 'id-group-2' ] = false;
    $subscriber->interests[ 'id-group-3' ] = false;
    return $subscriber;
    });

    However, when I send a comment, I receive the following Fatal Error (functions.php on line 145 is mc4wp_integration_wp-comment-form_data filter).

    Fatal error: Uncaught TypeError: Argument 1 passed to {closure}() must be an instance of MC4WP_MailChimp_Subscriber, array given, called in /URL/wp-includes/class-wp-hook.php on line 288 and defined in /URL/wp-content/themes/my-thema/functions.php:145 Stack trace: #0 /URL/wp-includes/class-wp-hook.php(288): {closure}(Array) #1 /URL/wp-includes/plugin.php(203): WP_Hook->apply_filters(Array, Array) #2 /URL/wp-content/plugins/mailchimp-for-wp/includes/integrations/class-integration.php(384): apply_filters('mc4wp_integrati...', Array, 45) #3 /URL/wp-content/plugins/mailchimp-for-wp/integrations/wp-comment-form/class-comment-form.php(94): MC4WP_Integration->subscribe(Array, 45) #4 /web/htdocs in /URL/wp-content/themes/my-thema/functions.php on line 145

    Plugin Contributor Lap

    (@lapzor)

    You can also get the group ID from MailChimp for WP > MailChimp page.

    Can you show me the code in your functions.php as you have it now, especially line 145?

    Thanks.

    Thread Starter VinzClortho

    (@vinzclortho)

    Hello,
    I had reported in my previous message the code of line 145 (it’s exactly like the code you wrote to me, I just added the IDs):

    add_filter( 'mc4wp_integration_wp-comment-form_data', function( MC4WP_MailChimp_Subscriber $subscriber ) {
    // replace “interest-id” with the actual ID of your interest.
    $subscriber->interests[ 'category_id' ] = true;
    // repeat for all interests you want to enable or disable
    $subscriber->interests[ 'id-group-1' ] = true;
    $subscriber->interests[ 'id-group-2' ] = false;
    $subscriber->interests[ 'id-group-3' ] = false;
    return $subscriber;
    });

    (of course I write here category_id, id-group-1, etc … just to not report the real code in this post)

    In the rest of function.php there are no other functions or hooks regarding mailchimp or the comment form.

    In the MailChimp for WP > MailChimp page, I can find list_id. In the MailChimp for WP > Form page, I can find the category_id (code of the interest field), but not the IDs of the individual groups contained (group-1, group-2, etc.). If I understand correctly, in your code I have to enter the IDs of each group in which I want to register the user ($subscriber->interests[ ‘id-group-1’ ] = true;).

    • This reply was modified 6 years, 1 month ago by VinzClortho.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Conflict of integration between CF7 and comment form’ is closed to new replies.