Symfony / Twig: How to get error message from hidden fields
I have defined 3 hidden fields in my form type:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('type', 'hidden', array(
))
->add('number', 'hidden', array(
))
->add('token', 'hidden', array(
))
;
}
When I submit my form, I get a notValid error from my controller, this is absolutely correct. But when I want to get errors in my twig template, there were no errors.
{{ dump(myForm.card.type.vars.errors|length) }} //<--- IS ALWAYS 0
But when I change the form fields to "text"
instead "hidden"
, I get the correct length of 3.
The difference is to get erros for hidden fields?
THANKS FOR ANY HELP !!
+3
source to share
1 answer
I also meet this problem today, my solution is:
Set error_bubbling as false
$form->add('shippingAddress', 'hidden', [
'label' => 'acme.form.checkout.addressing.shipping_address',
'data' => $addressId,
'error_bubbling'=>false
]);
Show error using this method
{{ form_label(form.shippingAddress) }} {{ form_errors(form.shippingAddress) }} {{ form_widget(form.shippingAddress) }}
+3
source to share