• Resolved Pete

    (@peezey01)


    Hi,

    I’ve added the following code to functions.php

    add_action( 'mctb_before_submit_button', function() {
        echo '<input type="hidden" name="SOURCE" id="SOURCE" value="MC4WP TopBar" />';
    });
    
    add_filter( 'mctb_data', function( $vars ) {
        $vars['SOURCE'] = ( isset( $_POST['SOURCE'] ) ) ? sanitize_text_field( $_POST['SOURCE'] ) : '';
        return $vars;
    });

    And when I inspect the HTML of the live page in Chrome it shows the following above the submit button:
    <input type="hidden" name="SOURCE" id="SOURCE" value="MC4WP TopBar">

    But MailChimp doesn’t pick up any value for SOURCE. How can I get it to work?

    I also added the following line to the form of the regular MC4WP plugin (not the top bar) and it works fine:
    <input type="hidden" name="SOURCE" id="SOURCE" value="MC4WP OnPage" />

    Cheers,
    Pete

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

    (@lapzor)

    Could you test to see if this works:

    add_filter( ‘mctb_data’, function( $vars ) {
    $vars[‘SOURCE’] = ‘TESTING’;
    return $vars;
    });

    If it doesn’t we know we have to look at your functions.php, if it does we have to look at how the topbar dat is submitted.

    Thanks for letting us know.

    Thread Starter Pete

    (@peezey01)

    Thanks for replying!

    I added the following…

    add_action( 'mctb_before_submit_button', function() {
        echo '<input type="hidden" name="SOURCE" id="SOURCE" value="MC4WP TopBar" />';
    });
    
    add_filter( ‘mctb_data’, function( $vars ) {
    $vars[‘SOURCE’] = ‘TESTING’;
    return $vars;
    });

    to functions.php.

    It didn’t work. The ‘Source’ field within Mailchimp is still blank.

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hey Pete,

    Can you please try below code instead (please comment out or remove the previous code)

    add_filter( 'mctb_data', function($data) {
    	$data['SOURCE'] = "MC4WP TopBar";
    	return $data;
    });

    I noticed an issue with the formatting of the previous code.

    Thread Starter Pete

    (@peezey01)

    Worked like a charm. Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Adding form field to Top Bar not working’ is closed to new replies.