I have an entity with age
.
I created a search form to show records where ageMin
< age
< ageMax
.
So I added non mapped form fields ageMin
and ageMax
:
$builder
->add('ageMin', IntegerType::class, [
'mapped' => false,
'required' => false
])
->add('ageMax', IntegerType::class, [
'mapped' => false,
'required' => false
])
;
I would like to check if the user has entered min greater than max (very simple requirement!).
I tried Symfony validate form with mapped false form fields but it is for symfony 2 and Components required is confusing for me.
I found these help pages too: https://symfony.com/doc/current/form/without_class.html#form-option-constraints and tried:
->add('ageMin', IntegerType::class, [
'mapped' => false,
'required' => false,
'constraints' => new LessThan('ageMax')
])
There are no errors but it doesn't work.
Other page: https://symfony.com/doc/current/validation/raw_values.html