I have a dynamically generated form with only one field. This field varies from query to query. I need to validate this field with right validator. I thought that the simple way would be creating form with this one field and validate whole form. But I was wrong. Form is validated with whole entity (not just one field).
I need form because every field of my entity can has own validation rule (it can be email validation, length validation or range validation and so on). And form will catch all these validations just by field name. Also it can transform some data to appropriate format.
And now I have a question: how can I validate only one particular field of the form?
$value = trim($request->get($field, '');
$form = $this->createFormBuilder($order, array('csrf_protection' => false))
->add($field)
->getForm();
$form->submit(array($field => $value));
if ($form->isValid()) {
$em->persist($order);
$em->flush();
}