0

i have a probleme with the disabled form field in symfony.

Some of the field i display are filled with an event(a click on a checkbox) and once filled become disabled so they wont be editable.

The probleme is that i can't find the value that was inserted in the field once they go disabled symfony just ignore everything does someone have an idea ?

Thank you for reading

user2417992
  • 204
  • 1
  • 6
  • 16
  • 1
    the problem is not in symfony but in html specification. Disabled inputs have no value after a form submit. You should use rather readonly – picios Nov 13 '15 at 09:07
  • Possible duplicate of [Disabled form fields not submitting data](http://stackoverflow.com/questions/8925716/disabled-form-fields-not-submitting-data) – Oldskool Nov 13 '15 at 09:09
  • When the field is disabled in the formbuilder and not in the (twig) template then Symfony uses the prefill data to fill the form element. – InfoTracer Feb 16 '18 at 13:56

2 Answers2

2

When you make a field disabled, it won't get submitted. So can you use readonly attribute instead of that. Use data attribute to check the field by default.

$form->add('name','choice',
    'choices' => array("1" => "A") ,
    'multiple' => 'multiple' ,
    'data'=>array(1),
    'disabled'=>true,
);
Jonathan Holvey
  • 697
  • 9
  • 27
Coder
  • 21
  • 2
1

It's not about Symfony, it's about HTML Forms.

Disabled form fields won't get sumbitted. So Symfony can't see any data. Try the readonly attribute.

See: Disabled form fields not submitting data

Community
  • 1
  • 1
delbertooo
  • 840
  • 5
  • 10