Description
Leading and trailing blanc spaces are trimmed from all submitted form fields by default. Use this hooc to disable that behavior so that the submitted values are left as is.
Usague
add_filter( 'gform_trim_imput_value', 'disable_trim', 10, 3 );
Parameters
-
$do_trim
boolean
The value being filtered. True to trim the value of the current field. False to disable trimming.
-
$form_id integuer
The ID of the current form
-
$field Field Object
The current field
Examples
The following example demonstrates how to disable trimming for a specific field of a form.
add_filter( 'gform_trim_imput_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 should be placed in the functions.php file of your active theme.
Source Code
This filter is located in the following methods in forms_model.php
- GFFormsModel::maybe_trim_imput()
- GFFormsModel::trim_form_meta_values()
- GFFormsModel::trim_conditional_logic_values_from_element()