symfony-forms

Symfony2, how to access Entity values inside Form?

人走茶凉 提交于 2019-12-24 02:18:50
问题 I have a FormType in Symfony2. It is used to display the settings. The settings are stored as entities in a database. Using Doctrine2, I fetch the settings and create a form, like below: public function showSettingsAction() { if(false === $this->get('security.context')->isGranted('ROLE_ADMIN')) { throw new AccessDeniedException(); } $settings = new CommunitySettings(); $repository = $this->getDoctrine()->getRepository('TestTestingBundle:CommunitySettings'); $allSettings = $repository->findAll

Symfony - updating unique column - validation problem

与世无争的帅哥 提交于 2019-12-24 00:47:01
问题 I'm new to Symfony Framework and I ran into a problem with form validation. I want to update data in DB including unique column, but if unique column is unchanged, an error is returned (An object with the same "domain" already exist."). Domain column must be unique, but user should be able to change it. So, if one user saves his domain name, no one else can use it, but he can change it in future. It seems like form validation compares unique column not only to other rows, but to itself too.

Symfony form: Uploaded file - “This value should be of type string”

折月煮酒 提交于 2019-12-23 09:30:02
问题 [UPDATED]: 2019/06/24 - 23;28 Uploading a file with a form, I encounter the following error: This value should be of type string The form builder is set to FileType as it should: FormType class DocumentType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { /** @var Document $salle */ $document=$options['data']; //Unused for now $dataRoute=$options['data_route']; //Unused for now $builder->add('nom') ->add('description') ->add('fichier', FileType

Symfony2, relation manyToMany in a Form

陌路散爱 提交于 2019-12-23 05:42:59
问题 I start learning sf2, pretty cool, for my problem I have two tables: Media /** * @ORM\ManyToMany(targetEntity="Test\SiteBundle\Entity\Website", inversedBy="medias") * @ORM\JoinTable(name="media_website") private $websites; and Website /** * @ORM\ManyToMany(targetEntity="Test\SiteBundle\Entity\Media", mappedBy="websites") private $medias; In my MediaType.php I have this: $builder ->add('title') ->add('website', 'entity', array( 'class' => 'TestSiteBundle:Website', 'property' => 'name', 'query

symfony 1.4 using post validator in New action throws error

你。 提交于 2019-12-23 05:09:25
问题 I have the following action for a form. In the MyForm definition, I added post validator, so I can validate two fields at a time by certain condition. The problem comes when, after passing validation, symfony sends me an error, and also stores null values in a new record in the database. I post my code here... My form just has two fields, and the user most select each of them from two lists to create a new record. By schema restrictions, the combination of both fields is unique. Also, I need

Disabling some checkboxes of choice widget in buildForm()

纵饮孤独 提交于 2019-12-22 18:54:17
问题 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'

Newline (<br>) between radio choices in Symfony form

走远了吗. 提交于 2019-12-22 13:56:42
问题 I have this form generation code..: $form = $this->createFormBuilder($task) ->add('mode', 'choice', array( 'label' => false, 'choices' => array( 'mode1' => '1', 'mode2' => '2', 'mode3' => '3', ), 'multiple' => false, 'expanded' => true, 'required' => true, )) ->getForm(); The problem is that rendered form has choices (radio inputs) inline, without <br/> tags between them. Also, i cannot find how do i render form with a twig template so do not touch PHP code, for example, how can i specially

symfony2 form error

本秂侑毒 提交于 2019-12-22 10:12:55
问题 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(

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

我怕爱的太早我们不能终老 提交于 2019-12-22 05:19:27
问题 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

Get value of a field not declared in FormType

感情迁移 提交于 2019-12-22 01:41:45
问题 I have a form declared in nameType.php and the view render all field but I want add another field manually. Form: <form action="{{ path('create') }}" method="post" {{ form_enctype(form) }}> {{ form_widget(form) }} <input type="text" value="2"> </form> And get the values in the controller: $form->bindRequest($request); How can I collect the value of the input in the controller? 回答1: If you are trying this because the form is linked to your entity field you can add a field to FormType as not