> For the complete documentation index, see [llms.txt](https://docs.super-forms.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.super-forms.com/developers/code-examples/trim-values-of-fields.md).

# Trim values of fields

{% hint style="info" %}
*Insert the below PHP code in your child theme functions.php file, or create a custom plugin. You may also use a plugin that allows you to insert code snippets to your site.*
{% endhint %}

### **Trim all fields:**

```php
add_filter('super_before_sending_email_data_filter', '_super_trim_all_values', 10, 2);
function _super_trim_all_values($data, $atts){
    foreach($data as $k => $v){
        if(isset($data[$k]['value'])) {
            $data[$k]['value'] = trim($data[$k]['value']);
        }
    }
    return $data;
}
```

### **Trims only specific fields:**

```php
add_filter('super_before_sending_email_data_filter', '_super_trim_values', 10, 2);
function _super_trim_values($data, $atts){
    // REPLACE 123 WITH YOUR FORM ID
    $id = 123;
    // DEFINE FIELD NAMES TO TRIM
    $fieldNames = array(
        'first_name',
        'last_name',
        'email'
    );

    $form_id = absint($atts['post']['form_id']); // contains the form ID that was submitted
    if($form_id==$id){
        foreach($fieldNames as $name){
            if(isset($data[$name]) && !empty($data[$name]['value'])){
                $data[$name]['value'] = trim($data[$name]['value']);
            }
        }
    }
    return $data;
}

add_filter('super_before_sending_email_data_filter', '_super_trim_all_values', 10, 2);
function _super_trim_all_values($data, $atts){
    foreach($data as $k => $v){
        if(isset($data[$k]['value'])) {
            $data[$k]['value'] = trim($data[$k]['value']);
        }
    }
    return $data;
}
```
