Using Gravity Forms ‘gform_campaignmonitor_field_value’ PHP filter

The gform_campaignmonitor_field_value filter allows you to modify a value before it is sent to Campaign Monitor.

Usage

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

For a specific form, use the format gform_campaignmonitor_field_value_FORMID:

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

To target a specific field, use the format gform_campaignmonitor_field_value_FORMID_FIELDID:

add_filter('gform_campaignmonitor_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.

More information

See Gravity Forms Docs: gform_campaignmonitor_field_value

Examples

Use GF_Field::get_value_export

This example shows how to use GF_Field::get_value_export() to format the field value for export, for Campaign Monitor add-on versions older than 3.4. Requires Gravity Forms 1.9.12.4 or higher.

add_filter('gform_campaignmonitor_field_value', 'format_entry_value', 10, 4);

function format_entry_value($value, $form_id, $field_id, $entry) {
    $form  = GFAPI::get_form($form_id);
    $field = GFFormsModel::get_field($form, $field_id);

    if (is_object($field)) {
        $value = $field->get_value_export($entry, $field_id, true);
    }

    return $value;
}

Change Signature Value

This example demonstrates how to send the URL of the signature image.

add_filter('gform_campaignmonitor_field_value', 'change_signature_value', 10, 4);

function change_signature_value($value, $form_id, $field_id, $entry) {
    $form  = GFAPI::get_form($form_id);
    $field = GFFormsModel::get_field($form, $field_id);

    if (is_object($field) && $field->get_input_type() == 'signature') {
        $value = RGFormsModel::get_upload_url_root() . 'signatures/' . $value;
    }

    return $value;
}

Place this code in the functions.php file of your active theme.