symfony-forms

Disabling some checkboxes of choice widget in buildForm()

折月煮酒 提交于 2019-12-06 04:45:10
I have a form widget of type "choice" which is being displayed as a list of many checkboxes. Everything works great. So to stress it out: there is ONE widget, with MANY checkboxes (and NOT several checkbox widgets). Now, I want to disable some of those checkboxes. The data for that is avaliable in the $options-Array. Here is the buildForm()-function of my FooType.php ... public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('foo', 'choice', array('choices' => $options['choiceArray']['id'], 'multiple' => true, 'expanded' => true, 'disabled' => $options[

Bootstrap 3 not working in Symfony3

徘徊边缘 提交于 2019-12-06 02:56:32
问题 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

Symfony2 - Where should I put files uploaded by users? [closed]

℡╲_俬逩灬. 提交于 2019-12-06 02:28:22
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . I am new with Symfony and I put images uploded by users under /web/bundles/mybundle/images/ directory. But I feel it's not good practice. Because when I run command below to create symlinks to other files under src directory. All images uploaded by users were removed. php app

Cloning object after getting data from a form in Symfony2

你离开我真会死。 提交于 2019-12-06 01:23:30
I'm sure I'm missing something very basic here. I have a form, and when the user updates the fields of the form I don't want to update the underlying entity but want to create a new entity with the new values. To clone Doctrine entities I followed the indication here . So my code is (let's say I want to clone the object with id=3: $id = 3; $storedBI = $this->getDoctrine() ->getRepository('AppBundle:BenefitItem') ->find($id); $form = $this->createForm(new BenefitItemFormType(), $storedBI); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $newBI =

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

北城以北 提交于 2019-12-06 00:58:24
问题 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

symfony2 form error

筅森魡賤 提交于 2019-12-05 22:40:40
The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, but is an instance of class Ecs\CrmBundle\Entity\Customer. Is the error I get in my browser.. FORM CODE: <?php namespace Ecs\CrmBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; class CustomerDefaultConfigType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name') ->add('customerStatus') ->add('tags', null, array('multiple' => true, 'property' => 'tag_name')) ; } public function

Symfony2 Form Event PreSetData Subscriber

百般思念 提交于 2019-12-05 12:29:52
In my Application the user can create Custom Fields for some entities and then set the values for this custom fields for each entity object when i display a form. The implementation is like this: 1º) I created a Interface for the forms, and the forms that i want implement this Interface. 2º) I created a form extension for all forms: app_core_form_builder.form_extension: class: App\Core\Bundle\FormBuilderBundle\Form\FormExtension arguments: ["@service_container", "@doctrine.orm.entity_manager"] tags: - { name: form.type_extension, alias: form } 3º) In this extension if the form implements the

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

杀马特。学长 韩版系。学妹 提交于 2019-12-05 10:07:28
问题 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:

Validate a dynamically populated choice field

白昼怎懂夜的黑 提交于 2019-12-05 07:59:44
I've got two choice fields, one depending on the other. When building the form the depending field got an empty choices' array. I then fill this field in JavaScript requesting some datas from an action. The issue comes from validation. Of course it doesn't pass because single or multiples values can't be valid against empty value. To solve that I've created a PRE_BIND listener which basically remove then recreate the choice field with the right values, but it still doesn't pass validation. $form->getErrors() returns nothing but $form->getErrorsAsString() returns me an error on my choice field.

How do I get Symfony forms to work with a REST API?

↘锁芯ラ 提交于 2019-12-05 07:32:00
I'm currently trying to get symfony forms to work with my post and put rest api endpoint. Currently I have: $request = $this->getRequest(); $cc = new CreditCard(); $form = $this->createForm(new CreditCardType(), $cc); $form->handleRequest($request); if ($form->isValid()) { //... } However, the form is never valid. Looking into the problem, it seems that the form's isSubmitted field is false, so it never passes validation. Also, since this is an api call, I have the csrf_protection set to false in the creditcardtype. Here is an example of what data I'm having the user submit: { "credit_card": {