Symfony Form Validation
Constraints EqualTo
and NotEqualTo
, has a propertyPath
attribute, which starts traverse from "self" field instance (displayed as Form
), so, to compare other field, must go to "root" form instance.
$this->createFormBuilder()
->add('field_one')
->add('field_two', [
'constraints' => [
new NotEqualTo(propertyPath: 'root[field_one].data'),
]
])
->getForm();