Description
This filter can be used to modify a value before it is sent to Campaign Monitor.
Usage
The base filter which would run for all forms and all fields would be used like so:
add_filter( 'gform_campaignmonitor_field_value', 'your_function_name', 10, 4 );
To target a specific form append the form id to the hook name. (format: gform_campaignmonitor_field_value_FORMID)
add_filter( 'gform_campaignmonitor_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_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.
Examples
1. Use GF_Field::get_value_export
This example shows how you can have versions of the Campaign Monitor add-on older than 3.4 use GF_Field::get_value_export() to format the field value for export. Requires a minimum of Gravity Forms 1.9.12.4.
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; }
2. Change Signature Value
This example shows how you can 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; }
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
gf_apply_filters( 'gform_campaignmonitor_field_value', array( $form['id'], $field_id ), $field_value, $form['id'], $field_id, $entry )
This filter is located in GFCampaignMonitor::maybe_override_field_value() in class-gf-campaignmonitor.php.
Since
The base filter was added in version 2.5. The form and field specific versions were added in version 3.4.