symfony-forms

Build a form having a checkbox for each entity in a doctrine collection

感情迁移 提交于 2019-11-27 08:06:40
I'm displaying an html table for a filtered collection of entities and I want to display a checkbox in each row as part of a form which will add the selected entities to a session var. I'm thinking that each checkbox should have the entity id as its value and I'll get an array of ids from the form field data (ok, so the value ought to be an indirect ref to the entity, but for the sake of simplicity). I've tried creating a form Type with a single entity type field, mapped to the id property of the entity and embedded into another form Type which has a collection type field. class

Symfony2.1 using form with method GET

倖福魔咒の 提交于 2019-11-27 02:53:45
问题 I need help on using Symfony2.1 forms with method=GET and a clean URL space. I am creating a "filter" which I'd like to set in the URL so that people can bookmark their links. So, very simply the code: $form = $this->createFormBuilder($defaultData) ->add('from', 'date', array('required' => false, 'widget' => 'single_text', 'format' => 'dd.MM.yyyy')) I render the form widget and all is fine. However when I submit the form, it produces very ugly GET parameters: /app_dev.php/de/event?form%5Bfrom

How can I add a violation to a collection?

▼魔方 西西 提交于 2019-11-27 02:53:24
问题 My form looks like this: public function buildForm(FormBuilderInterface $builder, array $options) { $factory = $builder->getFormFactory(); $builder->add('name'); $builder->add('description'); $builder->add('manufacturers', null, array( 'required' => false )); $builder->add('departments', 'collection', array( 'type' => new Department )); } I have a class validator on the entity the form represents which calls: if (!$valid) { $this->context->addViolationAtSubPath('departments', $constraint-

Symfony form - Access Entity inside child entry Type in a CollectionType

邮差的信 提交于 2019-11-27 00:45:24
问题 I'm trying to access the entity for a given embedded form in the parent CollectionType inside FormBuilder : ParentType Class ParentType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('children', CollectionType::class, array( 'entry_type' => ChildType::class ); } } ChildType class ChildType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $child = $builder->getData(); // this

Symfony validate form with mapped false form fields

﹥>﹥吖頭↗ 提交于 2019-11-26 23:59:39
问题 I've got a form with extra fields added with the option mapped to false . But when I try to validate my form, it won't pass indicating "this value is not valid" above these specific form fields. Isn't this option supposed to bypass validation? These form fields are only useful for populate other fields and I don't need to save or even check them. The only solution I found is to remove all extra fields with js on a submit button click. 回答1: This post is not up to date with Symfony 2.3 read

Description of Symfony2 form events?

女生的网名这么多〃 提交于 2019-11-26 23:58:32
问题 This is the FormEvents class from Symfony2 repository on github. It's linked from the main article, How to Dynamically Generate Forms Using Form Events. Anyone konws exactly when these events are called in the flow? namespace Symfony\Component\Form; /** * @author Bernhard Schussek <bernhard.schussek@symfony.com> */ final class FormEvents { const PRE_BIND = 'form.pre_bind'; const POST_BIND = 'form.post_bind'; const PRE_SET_DATA = 'form.pre_set_data'; const POST_SET_DATA = 'form.post_set_data';

Build a form having a checkbox for each entity in a doctrine collection

谁都会走 提交于 2019-11-26 22:17:25
问题 I'm displaying an html table for a filtered collection of entities and I want to display a checkbox in each row as part of a form which will add the selected entities to a session var. I'm thinking that each checkbox should have the entity id as its value and I'll get an array of ids from the form field data (ok, so the value ought to be an indirect ref to the entity, but for the sake of simplicity). I've tried creating a form Type with a single entity type field, mapped to the id property of

How to disable specific item in form choice type?

谁都会走 提交于 2019-11-26 20:30:18
问题 I have a form with choice field of entities from database: public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('categories', 'document', array( 'class' => 'Acme\DemoBundle\Document\Category', 'property' => 'name', 'multiple' => true, 'expanded' => true, 'empty_value' => false )); } This form will produce the list of checkboxes and will be rendered as: [ ] Category 1 [ ] Category 2 [ ] Category 3 I want to disable some of the items by value in this list but

Symfony2 Setting a default choice field selection

巧了我就是萌 提交于 2019-11-26 18:43:58
I am creating a form in the following manner: $form = $this->createFormBuilder($breed) ->add('species', 'entity', array( 'class' => 'BFPEduBundle:Item', 'property' => 'name', 'query_builder' => function(ItemRepository $er){ return $er->createQueryBuilder('i') ->where("i.type = 'species'") ->orderBy('i.name', 'ASC'); })) ->add('breed', 'text', array('required'=>true)) ->add('size', 'textarea', array('required' => false)) ->getForm() How can I set a default value for the species listbox? Thank you for your response, I apologise, I think I should rephrase my question. Once I have a value that I

Symfony2 Setting a default choice field selection

怎甘沉沦 提交于 2019-11-26 12:16:06
问题 I am creating a form in the following manner: $form = $this->createFormBuilder($breed) ->add(\'species\', \'entity\', array( \'class\' => \'BFPEduBundle:Item\', \'property\' => \'name\', \'query_builder\' => function(ItemRepository $er){ return $er->createQueryBuilder(\'i\') ->where(\"i.type = \'species\'\") ->orderBy(\'i.name\', \'ASC\'); })) ->add(\'breed\', \'text\', array(\'required\'=>true)) ->add(\'size\', \'textarea\', array(\'required\' => false)) ->getForm() How can I set a default