• Resolved labtecdxmp

    (@labtecdxmp)


    Hello,

    I have added a Name Field and a Select Dropdown (Interest Group).

    I have added the code for interest groups:

    add_filter( 'mctb_data', function($data) {
    
    	// make sure we have an array to work with
    	if( ! isset( $data['INTERESTS'] ) ) {
    		$data['INTERESTS'] = array();
    	}
    
    	// replace "interest-id" with the actual ID of your interest.
    	$data['INTERESTS'][] = "d467c984b7";
    
    	return $data;
    });

    And also the hook for the Name field:

    add_filter( 'mctb_data', function( $vars ) {
        $vars['FNAME'] = ( isset( $_POST['FNAME'] ) ) ? sanitize_text_field( $_POST['FNAME'] ) : '';
        return $vars;
    });

    The Name field comes through but the Group data doesn’t.

    My whole code is this:

    add_filter( 'mctb_data', function( $vars ) {
        $vars['FNAME'] = ( isset( $_POST['FNAME'] ) ) ? sanitize_text_field( $_POST['FNAME'] ) : '';
        return $vars;
    });
    
    add_filter( 'mctb_data', function($data) {
    
    	// make sure we have an array to work with
    	if( ! isset( $data['INTERESTS'] ) ) {
    		$data['INTERESTS'] = array();
    	}
    
    	// replace "interest-id" with the actual ID of your interest.
    	$data['INTERESTS'][] = "d467c984b7";
    
    	return $data;
    });

    I have tried to use 1 ‘mctb_data Hook and combine the 2 data but it doesn’t work.

    Do you know what I’m doing wrong?

    Many thanks for any help you can give me.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Lap

    (@lapzor)

    You simply want to set the interest group to that specific ID, there is no option or droppdown select for that in your code, right?
    Are you sure the interest group ID is correct? You can see the ID under Mailchimp for WP > Mailchimp after you fold open the list by clicking on the list name.

    Combining into one filter should work:

    add_filter( 'mctb_data', function( $data ) {
        $data['FNAME'] = ( isset( $_POST['FNAME'] ) ) ? sanitize_text_field( 
        $_POST['FNAME'] ) : '';
        // make sure we have an array to work with
        if( ! isset( $data['INTERESTS'] ) ) {
    	$data['INTERESTS'] = array();
        }
    
        // replace "interest-id" with the actual ID of your interest.
        $data['INTERESTS'][] = "d467c984b7";
    
        return $data;
    });

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

    Thread Starter labtecdxmp

    (@labtecdxmp)

    Hi Lap,

    Thank you for your reply and the code.

    When I generate the code for ‘Embedded Forms’ in Mailchimp, it provides me this code for the Select Dropdown

    //Add Select field to Mailchimp Bar
    add_action( 'mctb_before_submit_button', function() {
        echo '<select name="group[343831]" class="REQ_CSS select-css" id="group[343831]">
    	<option value="">How do you identify?</option>
    	<option value="16">some option</option>
    <option value="32">some option 1</option>
    <option value="64">some option 2</option>
    <option value="128">some option 3</option>
    <option value="256">some option 4</option>
    <option value="512">some option 5</option></select>';
    	
    });

    I’ve added this to Top Bar Form. The ID I used in the ‘interest-id’ is 100% correct.

    Plugin Contributor Lap

    (@lapzor)

    So you add code from an embedded form form Mailchimp to the topbar??
    That won’t work. They use different IDs (and field names)…

    And also the code you’re using on the data side is really just setting the interest group to that 1 specific interest group ID, it doesn’t look at the post value at all.

    Writing custom code is out of scope for our support, I recommend you ask a WordPress developer to take a look at our example code snippet and write the correct code for you.

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

    Thread Starter labtecdxmp

    (@labtecdxmp)

    Thanks for your reply.

    So currently there is no way to send Select Option data to Mailchimp? It has to be done by a developer?

    Many thanks

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hey @labtecdxmp,

    Yes, that is correct. Our example code does only sets the interest group and does not consider the value sent via the form. You can modify the code of the name fields and modify it to include the value of the interest group.

    Thread Starter labtecdxmp

    (@labtecdxmp)

    I think i’ll just look through your main MC4WP Files and see how you process the Select Dropdown.

    Thanks.

    Thread Starter labtecdxmp

    (@labtecdxmp)

    Failing that I’ll uninstall it and go another route.

    I thought a plugin was created so people don’t need to hire developers. To use the Top Bar add-on efficiently, you need to be a developer? Wow. Okay.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Name and Select Dropdown’ is closed to new replies.