• Resolved Ambyomoron

    (@josiah-s-carberry)


    I come back to a function discussed earlier:

    add_filter( 'yikes-mailchimp-filter-before-submission', 'maybe_supply_FNAME_to_merge_field', 10, 1 );
    
    function maybe_supply_FNAME_to_merge_field( $merge_fields ) {
    	if ( empty( trim( $merge_fields['SALUTATION'] ) ) && ! empty( $merge_fields['FNAME'] ) ) {
    		$merge_fields['SALUTATION'] = $merge_fields['FNAME'];
    	}
    	return $merge_fields;
    }

    It turns out that the expression

    empty( trim( $merge_fields['SALUTATION'] ) )

    always returns TRUE, whether the subscriber has entered a value in the SALUTATION field of the form or not.

    I have confirmed that the merge field SALUTATION is correctly set in the Yikes form

    I have also tried the expression:
    !isset( $merge_fields['SALUTATION'] )
    with the same result.

    So how to fix that?

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

    (@yikesitskevin)

    Hi Josiah,

    The only way that empty( trim( $merge_fields['SALUTATION'] ) ) would return true in every instance is if $merge_fields['SALUTATION'] doesn’t exist. Can you show me your form so I can see which field SALUTATION is? It might be keyed off the MERGE tag (i.e. MMERGE4 instead of the re-named key SALUTATION).

    Thread Starter Ambyomoron

    (@josiah-s-carberry)

    OK. Thanks for the hint. It turned out there was an error in my form. When I fixed it, the function worked correctly.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Awesome ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Detecting empty merge fields’ is closed to new replies.