symfony-forms

symfony2 get all validation constraints on an entity (yml, xml, annotations)

不问归期 提交于 2019-11-30 21:51:06
Im trying to get all validation constraints on an entity and translate theses constraints to Jquery validation rules, right now im able to get annotation defined constraints (thanks to : Symfony2 get validation constraints on an entity ), but im having some trouble getting xml and yml ones. $xml_file_loader = new XmlFileLoader("path_to_my_project/vendor/friendsofsymfony/user-bundle\FOS\UserBundle\Resources\config\validation.xml"); Using a similar code means that i need to know beforehand where the xml/yml file is located, i m trying to write somehow a generic code that can do this

Customize widget's ID attribute in Twig

做~自己de王妃 提交于 2019-11-30 17:22:30
Is it possible to customize HTML 'id' attribute in Twig when rendering a widget with {{ form_widget(form.NAME_OF_THE_FIELD) }} ? Passing {'attr': {'id': 'SOMETHING'}} doesn't work... Thanks for help! Matt Did you try: {{ form_widget(form.title, { 'id': 'my_custom_id' }) }} ? If this still doesn't work, you could also rely on form customization to handle it. But this could be overkill and may not be the best idea. Check the documentation on form theming for more info. As I said, maybe there is better way but this is only what I can propose you for now. Hope this helps. Ritesh Patadiya {{ form

symfony2 get all validation constraints on an entity (yml, xml, annotations)

断了今生、忘了曾经 提交于 2019-11-30 17:22:15
问题 Im trying to get all validation constraints on an entity and translate theses constraints to Jquery validation rules, right now im able to get annotation defined constraints (thanks to : Symfony2 get validation constraints on an entity), but im having some trouble getting xml and yml ones. $xml_file_loader = new XmlFileLoader("path_to_my_project/vendor/friendsofsymfony/user-bundle\FOS\UserBundle\Resources\config\validation.xml"); Using a similar code means that i need to know beforehand where

Customize widget's ID attribute in Twig

倾然丶 夕夏残阳落幕 提交于 2019-11-30 16:36:42
问题 Is it possible to customize HTML 'id' attribute in Twig when rendering a widget with {{ form_widget(form.NAME_OF_THE_FIELD) }} ? Passing {'attr': {'id': 'SOMETHING'}} doesn't work... Thanks for help! 回答1: Did you try: {{ form_widget(form.title, { 'id': 'my_custom_id' }) }} ? If this still doesn't work, you could also rely on form customization to handle it. But this could be overkill and may not be the best idea. Check the documentation on form theming for more info. As I said, maybe there is

Symfony2 form and Doctrine2 - update foreign key in assigned entities fails

白昼怎懂夜的黑 提交于 2019-11-30 15:54:25
问题 I have profiles and studies. One person can finish many studies. The form renders correctly. There is a button "Add new study" and with jQuery I add another subform based on data-prototype and this works well. When I submit such a form with new subforms I get an database error Integrity constraint violation: 1048 Column 'profile_id' cannot be null I understand this error but I don't know how to get rid of it. I know I can update collection of studies after binding in controller but I hope

Symfony2 form and Doctrine2 - update foreign key in assigned entities fails

安稳与你 提交于 2019-11-30 15:26:23
I have profiles and studies. One person can finish many studies. The form renders correctly. There is a button "Add new study" and with jQuery I add another subform based on data-prototype and this works well. When I submit such a form with new subforms I get an database error Integrity constraint violation: 1048 Column 'profile_id' cannot be null I understand this error but I don't know how to get rid of it. I know I can update collection of studies after binding in controller but I hope there is a way to configure it properly in annotations. When I only update entities everything works fine.

Which is the suggested place to modify binded form data in Symfony?

自闭症网瘾萝莉.ら 提交于 2019-11-30 10:52:11
问题 I've a form for creating a new Customer . A customer may have a mobile number. Mobile number should be persisted without + or 00 prefix that user can type. This can be accomplished easly with: $customer->setMobile(preg_replace("/^(\+|00)/", '', $customer->getMobile())); Which is the best place to put this code? Inside a CustomerController prior to call entity manager and persist the entity. Is this really a matter of a controller in MVC pattern? Using a SanitizeCustomerSubscriber and

How do I add an unbound field to a form in Symfony which is otherwise bound to an entity?

梦想的初衷 提交于 2019-11-30 06:10:46
Maybe I'm missing the obvious but how do I (or can I) add an extra "unbound" field to a Symfony form that is otherwise bound to an entity? Let's say I have an entity with fields first_name and last_name . I do the typical thing in my form class buildForm method. $builder ->add('first_name') ->add('last_name') ; and this in my controller: $editForm = $this->createForm(new MyType(), $entity); That works nicely but I'd like to add another text box, let's call it "extra", and receive the value in the POST action. If I do $builder->add('extra')‍ , it complains that NoSuchPropertyException in

Specify different validation groups for each item of a collection in Symfony 2?

孤人 提交于 2019-11-30 03:30:00
[ Documentation about collection ] When embedding forms (collection type) is possible to specify validation groups for each item, based on the current item? It seems not working ATM. The TaskType form adding a collection of tags: // src/Acme/TaskBundle/Form/Type/TaskType.php // ... public function buildForm(FormBuilderInterface $builder, array $options) { // ... $builder->add('tags', 'collection', array( // ... 'by_reference' => false, )); } For example we have two tags (tag 1 and tag 2) and a new tag is added using the "Add" button (via JavaScript): ----------- | add tag | ----------- - tag 1

Symfony twig how to add class to a form row

爱⌒轻易说出口 提交于 2019-11-30 03:22:54
I am building a project in Symfony 2.3 using Twig. I want to add a class to the form row block. I am using a form theme file which contains: {% block form_row %} <div class="form-row"> {{ form_label(form) }} {{ form_widget(form) }} {{ form_errors(form) }} </div> {% endblock %} Now some of my form rows I want to add an extra class form-row-split . I can't figure out how to do this properly. The way I have it almost-working is: {% block form_row %} {% set attr = attr|merge({'class': 'form-row' ~ (attr.class is defined ? ' ' ~ attr.class : '') ~ (errors|length > 0 ? ' error' : '')} ) %} <div {{