# FormFieldValidations

## Introduction

FormFieldValidations are related to [FormFields](https://docs.api.intratool.de/api-reference/forms/form-fields) and describe how input fields should be validated when a [User](https://docs.api.intratool.de/api-reference/users) enters information or submits the [Form](https://docs.api.intratool.de/api-reference/forms/forms).

How a field should be validated is determined by it's [FormFieldValidationType](https://docs.api.intratool.de/api-reference/forms/form-field-validation-types) associated by thw `key` and the `config`.

## Model Definition

**Alias**

`formFieldValidation`

**Relations**

| Relation                                                                                                 | Key                       | Type       | Relation Field(s)               |
| -------------------------------------------------------------------------------------------------------- | ------------------------- | ---------- | ------------------------------- |
| [FormField](https://docs.api.intratool.de/api-reference/forms/form-fields)                               | `formField`               | Belongs to | `form_field_id`                 |
| [FormFieldValidationType](https://docs.api.intratool.de/api-reference/forms/form-field-validation-types) | `formFieldValidationType` | Belongs to | `form_field_validation_type_id` |

**Computed Properties**

* `validation_string` - The resulting validation string from the configuration

## \[Adm.] Create

Create a new `FormFieldValidation`.

**Definition**

<mark style="color:yellow;">`POST`</mark> `/api/administration/forms/fields/validations`

**Request Keys**

| Key                                |   Type  |                                                         Default                                                        | Description                                                                                                         |
| ---------------------------------- | :-----: | :--------------------------------------------------------------------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------- |
| `form_field_id` \*                 | integer |                                                            -                                                           | The related [FormField](https://docs.api.intratool.de/api-reference/forms/form-fields)                              |
| `form_field_validation_type_id` \* | integer |                                                            -                                                           | The related [FormFieldValidationTyp](https://docs.api.intratool.de/api-reference/forms/form-field-validation-types) |
| `config`                           |   json  | Default [FormFieldValidationTyp](https://docs.api.intratool.de/api-reference/forms/form-field-validation-types) config | The scheme how the data has to be stored to pass the validation                                                     |

Keys with `*` are required.

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/administration/forms/fields/validations', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'form_field_id' => 7,
        'form_field_validation_type_id' => 'email'
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "form_field_id": 7,
    "form_field_validation_type_id": "email",
    "config": {},
    "updated_at": "2019-01-25 14:47:40",
    "created_at": "2019-01-25 14:47:40",
    "id": 5,
    "validation_string": "email",
    "form_field_validation_type": {
      "id": "email",
      "default_config": {},
      "sort_number": 2,
      "created_at": "2019-01-21 00:00:00",
      "updated_at": "2019-01-21 00:00:00"
    }
  }
}
```

## \[Adm.] Update

Update an existing `FormFieldValidation` by `id`.

**Definition**

<mark style="color:blue;">`PUT`</mark> `/api/administration/forms/fields/validations/{id}`

**Request Keys**

| Key                             |   Type  | Description                                                                                                         |
| ------------------------------- | :-----: | ------------------------------------------------------------------------------------------------------------------- |
| `form_field_id`                 | integer | The related [FormField](https://docs.api.intratool.de/api-reference/forms/form-fields)                              |
| `form_field_validation_type_id` | integer | The related [FormFieldValidationTyp](https://docs.api.intratool.de/api-reference/forms/form-field-validation-types) |
| `config`                        |   json  | The scheme how the data has to be stored to pass the validation                                                     |

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('PUT', '/api/administration/forms/fields/validations/5', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'form_field_id' => 7,
        'form_field_validation_type_id' => 'required'
    ]
]);

```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 5,
    "form_field_id": 7,
    "form_field_validation_type_id": "required",
    "config": {},
    "created_at": "2019-01-25 14:47:40",
    "updated_at": "2019-01-25 14:55:21",
    "validation_string": "required",
    "form_field_validation_type": {
      "id": "required",
      "default_config": {},
      "sort_number": 1,
      "created_at": "2019-01-21 00:00:00",
      "updated_at": "2019-01-21 00:00:00"
    }
  }
}
```

## \[Adm.] Delete

Delete an existing `FormFieldValidation` by `id`.

**Definition**

<mark style="color:red;">`DELETE`</mark> `/api/administration/forms/fields/validations/{id}`

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('DELETE', '/api/administration/forms/fields/validations/5', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "count": 1
  }
}
```
