I am using Symfony 3.2. I have a text field on a Symfony form. I would like to apply a "sanitize" function on form submission. What is the best way to do this? Here is a snippet of the form. The filed in question is "comment". I would like to remove unwanted characters from it. I don't really want to do everything in the controller.
$form = $this->createFormBuilder(
array('items' => $orderItems))
->add('items', CollectionType::class,
array(
'entry_type' => ReturnItemType::class,
'entry_options' => array('label'=>false),
'allow_add' => true
)
)
->add('comment', TextareaType::class,
array(
'error_bubbling' => true,
'constraints' => array(
new NotBlank()
)
));
You can use symfony form events for this. For example PreSubmitEvent. To your form add
and