I have defined 3 hidden fields in my formtype:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('type', 'hidden', array(
))
->add('number', 'hidden', array(
))
->add('token', 'hidden', array(
))
;
}
When I send my form, I get a notValid Error from my Controller, thats totally correct. But when I want to get the errors in my twig-template, no errors were set.
{{ dump(myForm.card.type.vars.errors|length) }} //<--- IS ALWAYS 0
But when I change the formtype fields to "text"
instead of "hidden"
I get the correct length of 3.
Is it different to get the erros for hidden-fields?
THANKS FOR ANY HELP!!
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
]);
Display the error using this way
{{ form_label(form.shippingAddress) }}
{{ form_errors(form.shippingAddress) }}
{{ form_widget(form.shippingAddress) }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With