bookmark_bordergform_mailchimp_field_value

Description

Use this filter to modify a value before it is sent to the MailChimp API.

Usage

The base filter which would run for all forms and all fields would be used like so:

add_filter( 'gform_mailchimp_field_value', 'your_function_name', 10, 5 );

To target a specific form append the form id to the hook name. (format: gform_mailchimp_field_value_FORMID)

add_filter( 'gform_mailchimp_field_value_10', 'your_function_name', 10, 4 );

To target a specific field append both the form id and the field id to the hook name. (format: gform_mailchimp_field_value_FORMID_FIELDID)

add_filter( 'gform_mailchimp_field_value_10_3', 'your_function_name', 10, 4 );

Parameters

  • $value string

    The value to be modified.

  • $form_id integer

    The ID of the form being processed.

  • $field_id string

    The ID of the field being processed.

  • $entry Entry Object

    The entry currently being processed.

  • $merge_var_name string

    The name of the mapped MailChimp MMERGE field.

Examples

1. Format Birthday

This example takes the birthday and reformats it into mm/dd before sending.

add_filter( 'gform_mailchimp_field_value', 'change_birthday', 10, 4 );
function change_birthday( $value, $form_id, $field_id, $entry ) {
    //not the id for the birthday field, return value unchanged
    if ( $field_id != 4 ) {
        return $value;
    }

    $month = date( 'm', strtotime( $value ) ); //get month
    $day = date( 'd', strtotime( $value ) ); //get day
    $date = $month . '/' . $day; //build date into format needed by MailChimp
    return $date;
}

2. Format Signature

add_filter( 'gform_mailchimp_field_value', function ( $value, $form_id, $field_id, $entry, $merge_var_name ) {

    return $merge_var_name == 'SIGNATURE' ? RGFormsModel::get_upload_url_root() . 'signatures/' . $value : $value;
}, 10, 5 );

Placement

This code should be placed in the functions.php file of your active theme

Source Code

gf_apply_filters( 'gform_mailchimp_field_value', array( $form['id'], $field_id ), $field_value, $form['id'], $field_id, $entry, $this->merge_var_name )

This filter is located in GFMailChimp::maybe_override_field_value() in class-gf-mailchimp.php

Since

The base filter was added in version 2.0. The form and field specific versions were added in version 3.7.