I would like to remove the 'name' field from the form editor

I have the following function, but this will just move the ‘name’ field to the 'standard_fields` group. Am I missing something or is this a bug?

As you can see in the screenshot the “Naam” field (“Name” in English) has moved the the field group above it (Standard fields)

function disable_name_advanced_field_type($field_groups)
{

    // Loop through field groups
    foreach ($field_groups as &$group) {
        if ($group['name'] === 'advanced_fields') {
            // Loop through fields in the "advanced_fields" group
            foreach ($group['fields'] as $key => $field) {
                // Check for the "name" field and remove it
                if ($field['data-type'] === 'name') {
                    unset($group['fields'][$key]);
                }
            }
        }
    }
    return $field_groups;
}
add_filter('gform_field_groups_form_editor', 'disable_name_advanced_field_type');

What I would think what would happen running this function is that it gets unset from the advanced_fields and with it removed from the list.

I’ve also tried creating the same function twice and changing if ($group['name'] === 'advanced_fields') { to if ($group['name'] === 'standard_fields') {, but this does nothing.

The following will work for this purpose…

// remove Name field type from editor
add_filter( 'gform_add_field_buttons', function( $field_buttons ) {

    foreach( $field_buttons as &$field_group ) {
        
        if ( is_array( $field_group ) && array_key_exists( 'fields', $field_group ) ) {
            
            $field_group['fields'] = array_filter( $field_group['fields'], function( $field ) {
                return ! in_array( $field['data-type'], [ 'name' ] );
            } );

        }

    }

    return $field_buttons;

} );

Any other field types you might like to remove can be added as an item to the array within the array_filter function.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.