• Resolved Ambyomoron

    (@josiah-s-carberry)


    I am trying to configure the contact 7 integration but it fails.
    All plugins are latest versions.
    The Contact 7 part of the functionality works fine.
    I have two mandatory fields in the MailChimp list, FNAME and LNAME. In the Contact 7 form there are two corresponding fields, also named FNAME and LNAME. Thus, I add the following code to functions.php:

    function additional_contact_form_7_data( $merge_variables, $cf7_variables ) {
    
        // Check our $cf7_variables array for 'FNAME'
        if ( isset( $cf7_variables['FNAME'] ) ) {
    
            // Filter name and add it to our MailChimp merge variables array 
            $merge_variables['FNAME'] = filter_var( $cf7_variables['FNAME'], FILTER_SANITIZE_STRING );
        }
        if ( isset( $cf7_variables['LNAME'] ) ) {
    
            // Filter name and add it to our MailChimp merge variables array 
            $merge_variables['LNAME'] = filter_var( $cf7_variables['LNAME'], FILTER_SANITIZE_STRING );
        }
        return $merge_variables;
    }
    add_filter( 'yikes-mailchimp-contact-form-7', 'additional_contact_form_7_data', 10, 2 );

    When completing the form, there is no doubt that the fields FNAME and LNAME are completed, as I see them in the email that Contact 7 sends me.
    I can also confirm that the Contact 7 field for the subscriber’s email address is defined as ‘[email* your-email]’ and that the integration checkbox field is defined as ‘[yikes_mailchimp_checkbox]’.

    Nonetheless, no subscriber is recorded at MailChimp and no mail is sent to that subscriber by MailCHimp to confirm the subscription.
    The debug log contains the entry:
    Yikesinc_eme_missing_body Page: Checkbox Integrations || Type: Checkbox Integration Subscribe User || Time: 9 February 2019 11:45

    I am not sure how to interpret that message. What does “eme_missing_body” mean? Do you see what I have forgotten or done wrong?

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

    (@yikesitskevin)

    Hey Josiah,

    Are your CF7 fields named FNAME and LNAME? I think they’re usually your-firstname or your-name by default.

    The error you’re showing means the request body (i.e. merge fields, etc.) aren’t being sent to MailChimp.

    Do you have any other CF7 integrations going on at the same time? Is this a fresh install or one you have a lot of custom code for?

    Thread Starter Ambyomoron

    (@josiah-s-carberry)

    OK – thanks for the right questions. I think I have the culprit.

    I had hooked a filter, as follows:

    add_filter( 'yikes-mailchimp-checkbox-integration-body', 'yikes_customize_wooco_request_body', 10, 3 );
    function yikes_customize_wooco_request_body( $request_body, $integration_type, $list_id ) {
    
    	// Only run this for WooCo integrations.
    	if ( 'woocommerce_checkout_form' !== $integration_type ) {
    		return;
    	}
    	// all sorts of code that changes $request_body
            .....
    	return $request_body;
    }

    I guess the mistake is in:

     	if ( 'woocommerce_checkout_form' !== $integration_type ) {
    		return;
    	}

    What is the string that corresponds to the integration type of a CF7 form?

    The other questions you raise are not at issue.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Yup that’ll do it. Use contact_form_7 for the $integration_type. You should also be able to change return; to return $request_body; to return the original request body without going through the WooCo modifications. (This will allow you to either not modify CF7’s request body or to modify CF7’s request body in a separate function)

    Thread Starter Ambyomoron

    (@josiah-s-carberry)

    All sorted out. Thanks for your help.

    @yikesitskevin have you considered adding support for fields in CF7 in the plugin?

    I used mc4wp before this, and it doesn’t need you to edit functions.php. I don’t understand the trend, but dumping info specific to 1 plugin in 1 site into a functions.php which belongs to a theme that could be shared between many sites, seems strange.

    Also the fact that you spend time writing a GUI , only to tell users to go back to the text editor seems against WP in general.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @funsail,

    We include first name, last name, and email by default but nothing more. The checkbox integrations were built to include just email and the other fields have been added on over time.

    Also, functions.php is not shared between many sites unless you’re using a multisite setup, in which case you most definitely have a child theme, and in which case you would add the code to your child theme.

    We spent time writing a GUI that adds a checkbox to connect your email address to various integrations. You don’t need to edit any code in order for your checkbox to work. You need to edit code if you want more than just the basic fields.

    With all of that said, we do recognize that our checkbox integrations are one of the most popular features of the plugin and we’d like to enhance that UI.

    Thread Starter Ambyomoron

    (@josiah-s-carberry)

    I agree that it would be a useful enhancement to be able to match up CF7 fields to MailChimp fields via the admin UI, so as to update MailChimp records with data from a CF7 form (and similarly for WooCommerce).

    @yikesitskevin using genesis, all themes are child themes. And yes I share those with symlinks, because I want 1 copy of code, not a dozen versions I have to update.

    But even if I don’t symlink them, I don’t want site specific code in a child theme. A theme is a theme, it’s not site specific. This code is site AND plugin specific, AND tied to my MC implementation!

    Users are burdened with opening their host ssh to edit the functions.php, try to test/backup and risk breaking a live site. I don’t know any user who loves functions.php.

    @yikesitskevin with the CF7, what I’m saying is that [yikes_mailchimp_checkbox] only captures email, not name fields, unless you dump that functions.php.

    mc4wp captures all the fields, as long as their field names match the MC field names. Which is what that code in functions.php does, but w/o having to write an if statement for every single field.

    I mean, imagine 3 years from now you change MC from LNAME to LASTNAME. Your forms break, nobody knows why, can’t find the setting in the plugin, who’s going to remember to check functions.php? Or I change my genesis theme, same thing – forms break, who’s going to remember to check functions.php?

    Even if you had a textfield in the plugin where you can type code, at least that keeps all the info related to the plugin together.

    Any chance of doing this? I know CF7 does it stupid too. Just imagine you had this all set up. You change themes. Suddenly your form doesn’t do what you expect. How stupid is that?

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    We’ve been planning on reworking all of our integrations to provide a nicer UI and more options. It’s a big task though and it’s not at the top of our priority list.

    If you’re actively changing themes, chances are that more than just your form will behave differently. Also, we always recommend adding these custom functions to a child theme or by using a plugin that is not theme dependent.

    In my opinion, the bigger issue is that WordPress doesn’t offer you a theme independent functions.php file. Using filters and actions is a key part of WordPress core and plugin development and there should be an easier way to add to them your website.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Contact form 7 integration fails’ is closed to new replies.