# Validated field forms

**URL:** https://forum.djangoproject.com/t/validated-field-forms/32558
**Category:** Deployment
**Created:** [June 29, 2024, 8:37am UTC](https://forum.djangoproject.com/t/validated-field-forms/32558 "2024-06-29T08:37:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Gae58](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gae58/32/18215_2.png) [@Gae58](https://forum.djangoproject.com/u/Gae58)
#### Post date: [June 29, 2024, 8:37am UTC](https://forum.djangoproject.com/t/validated-field-forms/32558/1 "2024-06-29T08:37:00Z")

</div>

Hello I have a form with a boolean field and a date field.

```auto
    Suspended = models.BooleanField(default=False)
    SuspendedData = models.DateField(blank=True, null=True)

```

When the SuspendedField is True it should enable the SuspendedDateField and when it is False it should disable the SuspendedDateFields.  
In the frontEnd I inserted a js func and it works, for more control, I would like to insert the same control also in the backEnd but I am not clear if it should be inserted in the .Form file or in the view  
Thanks

---

<div class="post-metadata">

### Author: ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)
#### Post date: [June 29, 2024, 3:01pm UTC](https://forum.djangoproject.com/t/validated-field-forms/32558/2 "2024-06-29T15:01:16Z")

</div>

If I were doing this, I’d create a `clean` method for the form.

(You could handle this in the ` __init__ ` method, but that feels too “manual” to me.)

---

<div class="post-metadata">

### Author: ![Gae58](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gae58/32/18215_2.png) [@Gae58](https://forum.djangoproject.com/u/Gae58)
#### Post date: [June 30, 2024, 9:24am UTC](https://forum.djangoproject.com/t/validated-field-forms/32558/3 "2024-06-30T09:24:20Z")

</div>

Sorry I didn’t understand the answer.  
A clarification **init** is the func to prepare the data in the initial stage ?  
The check on the backend is later  
I am new to python and the flow of operations to be performed is still not clear to me. I was thinking about the view since in the post function you save the movement  
Is there any link to read where to understand the right way to approach the validation of the various fields ?

---

<div class="post-metadata">

### Author: ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)
#### Post date: [June 30, 2024, 12:03pm UTC](https://forum.djangoproject.com/t/validated-field-forms/32558/4 "2024-06-30T12:03:18Z")

</div>

> [@Gae58](#):
>
> Is there any link to read where to understand the right way to approach the validation of the various fields ?

First, I suggest you read the full page on [Working with forms](https://docs.djangoproject.com/en/5.0/topics/forms/) and then [Form and field validation.](https://docs.djangoproject.com/en/5.0/ref/forms/validation/)

Briefly, a Django form:

- Defines fields
- Generates HTML
- Validates submitted data
- Populates the fields with validated and cleaned data

> [@Gae58](#):
>
> A clarification ` __init__ ` is the func to prepare the data in the initial stage ?

This is not completely accurate. The ` __init__ ` method is a method called when an instance of a class is created.

This line:  
`form = MyForm()`  
_and_ this line:  
`form = MyForm(request.POST)`

are _each_ going to call the ` __init__ ` method of the class, because each line is creating a separate instance of the class.

For more information on Python classes, see [9. Classes — Python 3.12.4 documentation](https://docs.python.org/3/tutorial/classes.html)

---

<div class="post-metadata">

### Author: ![Gae58](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gae58/32/18215_2.png) [@Gae58](https://forum.djangoproject.com/u/Gae58)
#### Post date: [July 4, 2024, 5:01pm UTC](https://forum.djangoproject.com/t/validated-field-forms/32558/5 "2024-07-04T17:01:10Z")

</div>

I put the field control in the clean function
