symfony-forms

How to load form types in tests

六眼飞鱼酱① 提交于 2019-11-28 04:01:06
问题 <?php namespace Tabl\VenueBundle\Tests\Form; use Symfony\Component\Form\Test\TypeTestCase; use Tabl\VenueBundle\Entity\Venue; use Tabl\VenueBundle\Form\VenueType; class VenueTypeTest extends TypeTestCase { public function testSubmitValidData() { $formData = array( 'title' => 'Hello World', ); $type = new VenueType(); $form = $this->factory->create($type); $object = new Venue(); $object->setTitle('Hello World'); // submit the data to the form directly $form->submit($formData); $this-

Description of Symfony2 form events?

感情迁移 提交于 2019-11-28 03:09:30
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'; const BIND_CLIENT_DATA = 'form.bind_client_data'; const BIND_NORM_DATA = 'form.bind_norm_data'; const

Symfony validate form with mapped false form fields

陌路散爱 提交于 2019-11-28 03:04:40
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. David Jacquel This post is not up to date with Symfony 2.3 read comments bellow A new version is comming ! Validating non mapped fields in Form (Symfony 2.1.2)

Inherit form or add type to each form

北城以北 提交于 2019-11-28 00:03:41
问题 I am searching for an easy way to add a bundle of fields to each form. I have found a way to extend the AbstractType and use the buildForm method to add more fields. When creating the form I give the name of my new type (How to Create a Custom Form Field Type). In my opinion it is an easy way, but it is restricted to one type per form. Is there a better way to achieve anything like that? I have read the cookbook of symfony, but I have only found stuff how to extend an existing form not how to

Symfony 2 Create a entity form field with 2 properties

旧城冷巷雨未停 提交于 2019-11-27 23:15:47
问题 I am using symfony2 and have a form to save the relation of one user to some rules. These rules are setted by the admin user of the company. In this form, after I selected a user to update, I have to select wich rule this user have permission. The problem is that I may have more then one rule with the same name (it's another entity) but the values are different. So, when I build the selectbox I must show the name and the value like: Quantity of items - 10 Quantity of items - 20 Value of the

How to disable specific item in form choice type?

女生的网名这么多〃 提交于 2019-11-27 20:47:13
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 I don't know where I should intercept choice field items to do that. Does anybody know an solution?

is there a facility for generating scaffolding in a Symfony2 app?

試著忘記壹切 提交于 2019-11-27 18:26:05
问题 I've been doing searches on scaffolding in Symfony 2 and keep finding references to "generators" but so far have not been able to get scaffolding up and working. By "scaffolding" I'm referring to a way to point your tool at a database and have it generate views/forms to perform CRUD operations. This can be useful for quickly prototyping something, and/or build a rough admin tool for some of your database tables. It can also provide a starting point for some form you are building. Is this

Symfony3: is it possible to change the name of a form?

只愿长相守 提交于 2019-11-27 17:30:27
问题 With Symfony 2.7 , you could customize a form's name in your EntityType class with the method getName() This is now deprecated. Is there another way to do that with Symfony 3.0 ? I have custom prototype entry_rows for collections that I would need to use in different forms. Since the name of the rows is based on the form's name, I would need to change the later in order to use them with a different form. 回答1: You should implements the getBlockPrefix method instead of getName as described in

Use a conditional statement when creating a form

只谈情不闲聊 提交于 2019-11-27 11:00:42
问题 I would like to use a conditional statement when creating a form in Symfony. I am using a choice widget in general case. If the user selects the option " Other ", I would like to display an additional text box widget . I suppose this can be done in javascript, but how can I still persist the data from 2 widgets into the same property in my entity? I have this so far: $builder->add('menu', 'choice', array( 'choices' => array('Option 1' => 'Option 1', 'Other' => 'Other'), 'required' => false, )

Add error to Symfony 2 form element

有些话、适合烂在心里 提交于 2019-11-27 09:43:31
问题 I check some validation in my controller. And I want to add error to specific element of my form on failure. My form: use Symfony\Component\Form\FormError; // ... $config = new Config(); $form = $this->createFormBuilder($config) ->add('googleMapKey', 'text', array('label' => 'Google Map key')) ->add('locationRadius', 'text', array('label' => 'Location radius (km)')) ->getForm(); // ... $form->addError(new FormError('error message')); addError() method adds error to form, not to element. How