gform_hubspot_form_object_pre_save_feed

Description

Allows the HubSpot form object to be filtered before saving the feed.

Usage

The following would apply to all forms:

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

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

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

Parameters

ParameterTypeDescription
$hs_formarrayThe new HubSpot form to be created or the properties to be updated for an existing HubSpot form. Refer to HubSpot’s documentation for more information on the data used in the array.
$feed_metaarrayThe meta from the current Feed Object.
$form

Feed Object

The current Gravity Forms form object.
$existing_form

null|array

Null or the existing HubSpot form.

Examples

Add submit button text using displayOptions.

add_filter( 'gform_hubspot_form_object_pre_save_feed', 'change_hubspot_feed', 10, 4 );
function change_hubspot_feed( $hs_form, $feed_meta, $form, $existing_form ) {
	if ( ! isset( $hs_form['displayOptions'] ) ) {
		$hs_form['displayOptions'] = rgar( $existing_form, 'displayOptions', array() );
	}

	$hs_form['displayOptions']['submitButtonText'] = 'Submit the Form';

	return $hs_form;
}


Always create a contact for new email addresses and pre-populate known values.

add_filter( 'gform_hubspot_form_object_pre_save_feed', function ( $hs_form, $feed_meta, $form, $existing_form ) {
	if ( ! isset( $hs_form['configuration'] ) ) {
		$hs_form['configuration'] = rgar( $existing_form, 'configuration', array() );
	}

	// Always create contact for new email address.
	$hs_form['configuration']['createNewContactForNewEmail'] = true;

	// Pre-populate contact fields with known values.
	$hs_form['configuration']['prePopulateKnownValues'] = true;

	return $hs_form;
}, 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?

Since

This filter was added in HubSpot version 1.0.

Source Code

This filter is located in GF_HubSpot::generate_hubspot_form_object() in class-gf-hubspot.php.