gform_zapier_field_value

Description

This filter can be used to modify a value before it is sent to Zapier.

Usage

add_filter( 'gform_zapier_field_value', '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 the Zapier add-on 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_zapier_field_value', 'format_entry_value', 10, 4 );
function format_entry_value( $value, $form_id, $field_id, $entry ) {
	$field = GFAPI::get_field( $form_id, $field_id );

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

	return $value;
}

2. Change Signature Value

This example shows how you can send the url of the signature image. Uncomment the modifiers line if you want the file to download or be transparent when using the URL to access the image.

add_filter( 'gform_zapier_field_value', 'change_signature_value', 10, 3 );
function change_signature_value( $value, $form_id, $field_id ) {
	$field = GFAPI::get_field( $form_id, $field_id );

	if ( is_object( $field ) && $field->get_input_type() === 'signature' ) {
//		$field->set_modifiers( array( 'download', 'transparent' ) );
		$value = $field->get_value_url( $value );
	}

	return $value;
}

3. Entry Meta

This example shows how you can override multiple field values and send entry meta instead, using the field’s default value as the key to the meta in the entry object. For example if the field’s default value was transaction_id then that entry meta value will be sent to Zapier for that field.

add_filter( 'gform_zapier_field_value', 'change_field_value', 10, 4 );
function change_field_value( $value, $form_id, $field_id, $entry ) {
	// Only do this on form ID 31.
	if ( 31 !== $form_id ) { // Change 31 to your form id number.
		return $value;
	}

	// Change values for $fields to use your fields id numbers.
	$fields = array( 5, 6, 7 );
	if ( in_array( $field_id, $fields ) && ! empty( $value ) ) {
		$value = rgar( $entry, $value );
	}

	return $value;
}

4. Format Date Field Value

This example shows how you can send the date field.

add_filter( 'gform_zapier_field_value', 'format_date_value', 10, 4 );
function format_date_value( $value, $form_id, $field_id, $entry ) {
	$field = GFAPI::get_field( $form_id, $field_id );

	if ( is_object( $field ) && $field->get_input_type() == 'date' ) {
		$value = GFCommon::date_display( $value, $field->dateFormat );
	}

	return $value;
}

5. Replace US state name with state code

This example shows how you can send the state code instead of the state name.

add_filter( 'gform_zapier_field_value', function ( $value, $form_id, $field_id, $entry ) {
	if ( $form_id == 1 && $field_id == 2 ) {
		$value = GF_Fields::get( 'address' )->get_us_state_code( $value );
	}

	return $value;
}, 10, 4 );

6. Use gf-download URL

This example shows how you can replace the direct URL to the file, which is stored in the entry, with the more secure gf-download URL.

add_filter( 'gform_zapier_field_value', function ( $value, $form_id, $field_id, $entry ) {
	$field = GFAPI::get_field( $form_id, $field_id );

	if ( $field instanceof GF_Field_FileUpload ) {
		$value = $field->get_download_url( $value );
	}

	return $value;
}, 10, 4 );

7. Normalize JSON encoding of multiple file upload fields

This example shows how you can perform proper JSON encoding of multiple file upload fields.

add_filter( 'gform_zapier_field_value', function ( $value, $form_id, $field_id, $entry ) {
	$field = GFAPI::get_field( $form_id, $field_id );

	if ( $field instanceof GF_Field_FileUpload && $field->multipleFiles && ! empty( $value ) ) {
		$value = json_decode( $value );
	}

	return $value;
}, 10, 4 );

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

This filter is located in GFZapier::get_body() in zapier.php.