will give you data that you need.
I hope this helps.
It's an issue with field mapping. the data you're passing into the form needs to be applied to the field you're adding ('mythings') so you have to wrap $data in an array as a value to the key 'mythings'.
$data=array(); $choices=array(1 => 'A thing', 2 => 'This other thing', 100 => 'That other thing'); $fb=$this->createFormBuilder(array('mythings' => $data)); $fb->add('mythings', 'choice', array( 'choices' => $choices, 'required' => false, 'expanded' => true, 'multiple' => true)) ->add('save', 'submit', array('label' => 'Save')); $form=$fb->getForm();
you could try naming the array keys to preserve the actual index
$data=array(); $choices=array('1' => 'A thing', '2' => 'This other thing', '100' => 'That other thing'); $fb=$this->createFormBuilder($data); $fb->add('mythings', 'choice', array( 'choices' => $choices, 'data' => $data, 'required' => false, 'expanded' => true, 'multiple' => true, 'mapped' => false))-> add('save', 'submit', array('label' => 'Save')); $form=$fb->getForm();
- Symfony2 classless form with choices: retrieving submitted data
- Symfony2 POST data empty when form is submitted with certain files
- Form in modal with symfony2 and jquery is not being submitted with data
- Symfony2 - form entity field with multiple , data not preserved after choices set
- Symfony2 Form pre-fill fields with data
- Symfony2 form entity type with empty choices
- Symfony2 form validation groups based on submitted data
- Retrieve data from a form with GET method using symfony2
- Symfony2 Pre populate form with data from model?
- Symfony2 - Sending other data along with form data via Ajax causes IsValid() to return false
- Symfony2 updating data with a form
- Symfony2 Form with custom FormType calls DataTransformer with same data in both directions
- send data from angularjs form to symfony2 with Rest POST
- Why my form does not submitted with Ajax in symfony2
- Symfony2 Form Collection Field with Different Choices
- Add a required form field based on submitted data in Symfony2
- Symfony2 Form - "You cannot change the data of a submitted form."
- Howto show filled form with existing data on symfony2
- How to get the Id of an entity submitted with symfony2 form
- Symfony2 - using entity value as default when form is submitted with empty fields
- Symfony2 My custom form field type isn't populated with data from entity
- Symfony2 remove id field from submitted form data
- Symfony2 handle jQuery serialized Form and extra data sent with ajax post
- Symfony2 : data not binded to form with handleRequest()
- Fill my form with the data that I pick up from a table - Symfony2
- Auto populating form with existing data symfony2
- Add data to a submitted form object inside a controller in Symfony2
- Authenticate multiple symfony2 firewalls with one login form
- How to render a checkbox that is checked by default with the symfony2 Form Builder?
More Query from same tag
- How to handle Common data of ChoiceType with Symfony form?
- Nested list with TWIG in Symfony 2
- Symfony 4: Can find the file but not the class
- Cannot access files inside web folder Symfony (route not found)
- Clean usage of groups and roles in FOSUserBundle
- Symfony 3 doesn't authenticate user from database
- Doctrine cannot map entity/repository namespace in chain
- link in body of Email Symfony2
- How to manipulate username before signin in Symfony2 FOSUserBundle?
- symfony APi to YAML format for swagger
- Symfony\Doctrine createQueryBuilder() select 'not in' from a OneToMany relation
- Symfony Project, can't fixing file permissions
- Symfony "This value should not be blank." while submitting form
- How to fix 301 Moved permanently for Ajax request
- SoftDelete, Relations and the SonataORMAdminBundle
- Populate form from two entities
- JMS serializer serialize custom object and deserialize
- Symfony: multiple routes with different parameters with default null
- How can I load fixtures from functional test in Symfony 2
- Adding Captcha to Symfony2 Login Page
- Symfony2 use multiple role hierarchies
- Getter & Setter in Entity Class + Symfony2
- Several forms on same page
- Symfony 2 - Attempted to call function "apcu_fetch" from namespace "Doctrine\Common\Cache"
- Symfony Serializer empty objects
- symfony The file was found but the class was not in it
- Indecent number of queries with PHPCR/Jackalope Doctrine DBAL?
- Country-Currency mapping in symfony
- Symfony 3 - Forms choices: How to set 'disabled' = true on "placeholder"
- How can I access to parameters.yml content within a custom twig extension