formbuilder

How to translate labels in symfony2 forms with messages.en.yml?

ぃ、小莉子 提交于 2019-11-27 13:47:34
问题 I am trying to get translation of form fields to work. I have messages.en.yml in my Bundle's Ressource folder. test: it works form: description: Add a description. I want to build a form in an EntityType which translates the labels of the form fields accordingly. $builder->add( 'description', null, array('label' => 'form.description', 'required' => false) ); Yet only the literal string 'form.description' gets shown, not the expected translation of Add a description. The translation service

How to create a form with multiple rows of one entity in Symfony2

社会主义新天地 提交于 2019-11-27 06:51:47
问题 First I've read documents for both Collection Field Type and How to Embed a Collection of Forms ... The example is about one entity (Task) that has one-to-many relation with another entity (Tag), and I understand it, but I can not adapt it to what I want! To make it simpler, let say I have a Task entity, this task entity has some relations with other objects like user and project (each task can have one user and one project) I want to make one form, inside this form a list of Tasks, each task

Symfony 2 - how to pass data to formBuilder?

风格不统一 提交于 2019-11-27 03:56:12
I'm using entity choice list in my form. I want to use only specific entities (in example: only groups that user belongs to) So, in controller, I'm getting these groups, and trying to pass them into formBuider . Controller: /.../ $groups = $em->getRepository('VendorMyBundle:Group')->getUserGroups($user); $form = $this->createForm(new Message($groups), $message); /.../ so, what now? how to use it in formBuilder? how to change this line to use passed array of groups? ->add('group','entity',array('class' => 'Vendor\MyBundle\Entity\Group', 'label'=>'Group:')) or in the other way: class MessageType

How to set a class attribute to a Symfony2 form input

断了今生、忘了曾经 提交于 2019-11-27 03:29:17
How can I set the HTML class attribute to a form <input> using the FormBuilder in Symfony2 ? Something like this: ->add('birthdate', 'date',array( 'input' => 'datetime', 'widget' => 'single_text', 'attr' => array( 'class' => 'calendar' ) )) {{ form_widget(form.birthdate) }} I want this input field with the attribute class set to calendar Problematic You can do this from the twig template: {{ form_widget(form.birthdate, { 'attr': {'class': 'calendar'} }) }} From http://symfony.com/doc/current/book/forms.html#rendering-each-field-by-hand You can do it with FormBuilder. Add this to the array in

Rails AJAX: My partial needs a FormBuilder instance

爱⌒轻易说出口 提交于 2019-11-27 01:58:17
问题 So I've got a form in my Rails app which uses a custom FormBuilder to give me some custom field tags <% form_for :staff_member, @staff_member, :builder => MyFormBuilder do |f| %> [...] <%= render :partial => "staff_members/forms/personal_details", :locals => {:f => f, :skill_groups => @skill_groups, :staff_member => @staff_member} %> [...] <% end %> Now, this partial is in an area of the form which gets replaces by an AJAX callback. What I end up doing from the controller in response to the

Symfony2 file upload step by step

女生的网名这么多〃 提交于 2019-11-26 15:06:44
I am still learning Symfony2 and don't understand how to upload a file. Don't worry, I've already checked the documentation . It's really good, but my problem isn't explained in any tutorial. I am looking for guidance on how to upload a file with Symfony2 but with all the thing everybody needs (such as constraint of extension, rename of the file based on the id and stuff, store the path in the db, etc...) I found good tutorials, tried to mixed them but with no success. Each time a different problem appears: file re-uploads on every submit on the form (even if the file field is empty),

How to set a class attribute to a Symfony2 form input

为君一笑 提交于 2019-11-26 12:39:00
问题 How can I set the HTML class attribute to a form <input> using the FormBuilder in Symfony2 ? Something like this: ->add(\'birthdate\', \'date\',array( \'input\' => \'datetime\', \'widget\' => \'single_text\', \'attr\' => array( \'class\' => \'calendar\' ) )) {{ form_widget(form.birthdate) }} I want this input field with the attribute class set to calendar 回答1: You can do this from the twig template: {{ form_widget(form.birthdate, { 'attr': {'class': 'calendar'} }) }} From http://symfony.com

Symfony2 file upload step by step

三世轮回 提交于 2019-11-26 04:09:44
问题 I am still learning Symfony2 and don\'t understand how to upload a file. Don\'t worry, I\'ve already checked the documentation. It\'s really good, but my problem isn\'t explained in any tutorial. I am looking for guidance on how to upload a file with Symfony2 but with all the thing everybody needs (such as constraint of extension, rename of the file based on the id and stuff, store the path in the db, etc...) I found good tutorials, tried to mixed them but with no success. Each time a