gform_trim_input_value

Description

Leading and trailing blank spaces are trimmed from all submitted form fields by default. The gform_trim_input_value hook allows developers to disable that behavior so that the submitted values are left as is.

Usage

add_filter( 'gform_trim_input_value', 'disable_trim', 10, 3 );

Parameters

ParameterTypeDescription
$do_trimbooleanThe value being filtered. True to trim the value of the current field. False to disable trimming.
$form_idintegerThe ID of the current form.
$fieldField ObjectThe current field.

Examples

Disable trimming for a specific field.

The following example demonstrates how to disable trimming for a specific field of a form.

add_filter( 'gform_trim_input_value', 'disable_trim', 10, 3 );
function disable_trim( $do_trim, $form_id, $field ) {
	if ( $form_id == 36 && $field->id == '1' ) {
		return false;
	}

	return $do_trim;
}

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 the following methods in forms_model.php:

  • GFFormsModel::maybe_trim_input()
  • GFFormsModel::trim_form_meta_values()
  • GFFormsModel::trim_conditional_logic_values_from_element()