• Resolved branto

    (@branto)


    I’ve tried adapting the functions.php code below per the discussion on the website, but can’t seem to get it right.

    // add hidden field to top bar
    add_action( ‘mctb_before_submit_button’, function() {
    echo ‘<input type=”hidden” name=”INTERESTS[3794ae7c19][]” value=”807ce58ff6″ />’;

    });

    add_filter( ‘mctb_data’, function( $vars ) {
    $vars[‘INTERESTS[3794ae7c19][]’] = ( isset( $_POST[‘INTERESTS[3794ae7c19][]’] ) ) ? sanitize_text_field( $_POST[‘INTERESTS[3794ae7c19][]’] ) : ”;
    return $vars;
    });

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

    (@lapzor)

    I see it’s a hidden field, so it’s implicit? You don’t need the field then, we can just set it from code in the filter, like this:

    add_filter( 'mctb_data', function($data) {
    	$data['INTERESTS'][] = "interest-id";
    	return $data;
    });

    https://github.com/ibericode/mc4wp-snippets/blob/master/add-ons/top-bar/add-to-interest-groups.php

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

    Thread Starter branto

    (@branto)

    Thank you so much! This worked!

    But now a related issue — I have checked “Update existing subscribers?” in the advanced settings, which causes the form to replace any existing interests with the interest coded into the form.

    What I want is for the the interest coded into the form to be added to existing interests, not to replace them. Is this possible?

    Thank you so much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding hidden group’ is closed to new replies.