# 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;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.super-forms.com/developers/code-examples/trim-values-of-fields.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
