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


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


  • $do_trim boolean

    The value being filtered. True to trim the value of the current field. False to disable trimming.

  • $form_id integer

    The ID of the current form

  • $field Field Object

    The current 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;


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_input()
  • GFFormsModel::trim_form_meta_values()
  • GFFormsModel::trim_conditional_logic_values_from_element()