Answer the question
In order to leave comments, you need to log in
How to make additional input fields in symfony?
There is symphony 3, there is a form.
There is one input field and a button for creating more input fields, which must have the same name as the first field in order to be stored in one cell in the database.
Is there a correct symfony-way for this case?
This is the form creation:
$form = $this->createFormBuilder($list)
->add('list_elements', TextType::class, array( 'allow_extra_fields' => true, 'attr' => array('class' => 'form-control', 'style' => 'margin-bottom:15px')))
->add('add_element', ButtonType::class, array('attr' => array('class' => 'form-control', 'onclick' => 'addInput(\'form\');' ,'style' => 'margin-bottom:15px')))
->add('save', SubmitType::class, array('label'=>'Create List','attr' => array('class' => 'btn btn-primary', 'style' => 'margin-bottom:15px')))
->getForm();
Answer the question
In order to leave comments, you need to log in
To build a form (twig + forms) symfony.com/doc/current/cookbook/form/form_collect... +
To transform data into 1 field: symfony.com/doc/current/cookbook/form/data_transfo...
Such inputs should not be stored in one cell. Make a OneToMany relation and attach them to the form with collection. The data will be atomic and everything is as it should be :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question