symfony-forms

symfony2 customize form select options

不想你离开。 提交于 2019-12-04 10:32:23
问题 I'm trying to do a simple form to add an activity with a name and a color. So I want to make a list with some an array of color, for now it is working I have the name of the color. I can add any attribute to my select tag: $form = $this->createFormBuilder($myclass) ->add('Colors','choice',array('label'=>'select some colors', 'multiple'=>true, 'choices'=>array(1=>'red', 2=>'blue', 3=>'green'), 'attr'=>array('style'=>'width:300px', 'customattr'=>'customdata') )); The output will be something

Doctrine does not update a simple array type field

你离开我真会死。 提交于 2019-12-04 09:14:55
问题 Short Story (Edit) It is possible to store an array instead of a mapped association. In Symfony2, this is fairly easy using the collection Field Type. For example, using this technique, you could store an array of text fields that populate an array events field. However, to update an array, there is a trick, and this trick is beautifully explained by @Vadim Ashikhman in the accepted answer. Long Story Sometimes it is useful and more efficient to store an array instead of a mapped association.

Bootstrap 3 not working in Symfony3

匆匆过客 提交于 2019-12-04 08:12:39
I've just started to learn Symfony3, and I'm trying to theme my form using bootstrap3. According to the documentation , bootstrap_3_layout.html.twig is built-in and can be activated globally by altering the Twig settings in config.yml : # Twig Configuration twig: debug: "%kernel.debug%" strict_variables: "%kernel.debug%" form_themes: - "bootstrap_3_layout.html.twig" When I reload the page, the page loads without CSS, the twig file and page source are as follows: {# app/Resources/views/experiment/new.html.twig #} {{ form_start(form) }} {{ form_widget(form) }} {{ form_end(form) }} <form name=

Symfony forms (as standalone component with Doctrine) EntityType not working

雨燕双飞 提交于 2019-12-04 06:39:44
I'm using Symfony forms (v3.0) without the rest of the Symfony framework. Using Doctrine v2.5. I've created a form, here's the form type class: class CreateMyEntityForm extends BaseFormType { public function buildForm(FormBuilderInterface $builder, array $options){ $builder->add('myEntity', EntityType::class); } } When loading the page, I get the following error. Argument 1 passed to Symfony\Bridge\Doctrine\Form\Type\DoctrineType::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry, none given, called in /var/www/dev3/Vendor/symfony/form/FormRegistry.php on line 85

Symfony 2 - rearrange form fields

笑着哭i 提交于 2019-12-04 05:09:16
In our Symfony2 project we have a very complex structure for forms with embedded forms.... Now we got the requirement to bring the output of the form in an specific order. And here is the problem: We use the form_widget(form) and now we are looking for a solution in the object (e.g. via annotations) or the formbuilder to move a specific field to the end of the form. in symfony 1.4 it was the widget-movefield() function, i guess... Thx... You can re-order the fields using this bundle: https://github.com/egeloen/IvoryOrderedFormBundle This allows you to do things like this: $builder ->add('g',

Embed a Collection of Forms Error: Could not determine access type for property

こ雲淡風輕ζ 提交于 2019-12-04 00:12:27
I am trying to embed collection of Tag forms to Service form, according to this tutorial . Tag and Service entities have many-to-many relationship. Form is rendering correctly. But when I submit form, I get Could not determine access type for property "tagList" error. I don't understand why new Tag object is not added to the Service class by calling the addTag() method. ServiceType public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('title', TextType::class, array( 'label' => 'Title' )) ; $builder->add('tagList', CollectionType::class, array( 'entry_type'

using sonata_type_collection against a custom form type instead of a property/relationship with another entity

夙愿已清 提交于 2019-12-03 20:52:23
is it possible to use sonata_type_collection against a custom form type instead of a property/relationship with another entity? Something like this: $formMapper->add('foo', 'sonata_type_collection', array('type' => new \myVendor\myBundleBundle\Form\Type\BlockType() )); Which throws me the following error The current field `contingut` is not linked to an admin. Please create one for the target entity : `` EDIT: Something like this did the trick: $formMapper->add('contingut', 'collection', array( 'type' => new \myVendor\myBundleBundle\Form\Type\Block1Type(), 'allow_add' => true, 'allow_delete' =

Use Sonata Field Type on normal Form Class

血红的双手。 提交于 2019-12-03 17:22:43
I'm trying to insert custom sonata form field type on the front page, not in SonataAdmin, something like this: $form = $this->createFormBuilder($content) ->add('titleEs', 'text', array('required' => true, 'label' => 'label.title.spanish', 'attr' => array('class' => 'col-xs-12 form-control input-lg'))) ->add('contentEs', 'ckeditor', array('required' => true,'label' => 'label.content.spanish', 'attr' => array('class' => 'col-xs-12'))) ->add('titleEn', 'text', array('required' => true,'label' => 'label.title.english', 'attr' => array('class' => 'col-xs-12 form-control input-lg'))) ->add(

Create 2 different entities with same form in Symfony 2

邮差的信 提交于 2019-12-03 17:12:39
Is it possible to create 2 related entities with the same form and action? If yes, how? I want to create a new User and its related Questionnaire in a 1step registration. Thanks, Luca You can create a form type for related entity (Questionnaire) and use it as a field type in User form type. It's called form nesting. // src/Acme/DemoBundle/Form/Type/QuestionnaireType.php namespace Acme\DemoBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; class QuestionnaireType extends AbstractType { public function buildForm(FormBuilderInterface

Symfony2 choice field not working

删除回忆录丶 提交于 2019-12-03 16:26:57
I asked a question here How to use Repository custom functions in a FormType but nobody anwsered, so i did a little digging and advanced a little but i still get this error: Notice: Object of class Proxies\__CG__\Kpr\CentarZdravljaBundle\Entity\Category could not be converted to int in /home/kprhr/public_html/CZ_Symfony/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php line 457 Now this is how my CategoryType looks like: <?php namespace Kpr\CentarZdravljaBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form