symfony - Symfony2. Access to submitted values inside Form Class

When a form doesn't validate, I need to access the submitted data inside a Form Class in order I can set some options in a custom field. I have tried with $data = $builder->getForm()->getData();$data = $builder->getData();but $data has the empty object. So... what is the correct form to access the submitted data by the user after validation error in the form class?Thanks...Read more

symfony - How to Position Symfony2 Forms Error at proper place?

I am using Symfony form in my project, here is the code : Form : public function buildForm(FormBuilder $builder, array $options){ $builder->add('name', 'text', array('required' => true, 'error_bubbling' => true)); $builder->add('email', 'email', array('required' => true, 'error_bubbling' => true)); $builder->add('message', 'textarea', array('required' => true, 'error_bubbling' => true));}public function getDefaultOptions(array $options){ $constraintCollection = new Collection(array( 'name' => n...Read more

symfony - Symfony2 form validation - this value is not valid

I got a form in Symfony but it won't validate and I don't know why.From UserBundle/Entity/Task.php/** * * @ORM\ManyToMany(targetEntity="Project\TaskBundle\Entity\Task", inversedBy="users") * @ORM\JoinTable(name="project_users_tasks") * */protected $tasks;From UserBundle/Form/CreateUserFormType.php which is my formbuilder: $builder->add('tasks', 'entity', array( 'class' => 'TaskBundle:Task', 'query_builder' => function(EntityRepository $er) { return $er->createQueryBuilder('b') -&g...Read more

Symfony 2 : access to form config and submitted data in PRE_SUBMIT event

I'm currently trying to access to my form config (and its options) in a PRE_SUBMIT FormEvent callback. However, when I'm doing that for example :<?php// This is my callback function for the PRE_SUBMIT event on a formtype elementpublic function preSubmit(FormEvent $event){ $data = $event->getData(); $form = $event->getForm(); [...] $myConfig = $form->get('my_form_element_child')->getConfig()->get('my_option');?>It raises an exception saying : FormBuilder methods cannot be accessed anymore once the builder is tur...Read more

symfony - Symfony2 How to set data on a submitted form?

I am facing a tricky issue with one of my form.The underlying objects (entities) are pretty simple: Work ManyToOne Artist.Working on the WorkType form, my UI makes the field artist useless as I always do $work->setArtist($artist) before building the form with my filled object $work. Everything is OK. Thus, I have no artist field in this form. My form contains some fields that depend on the underlying artist value, hence I must set the artist before form is submitted (and not after).Now I am making a MasterType form in which I embed a WorkTyp...Read more

fosuserbundle - Symfony 4.0 FOSUser Bundle 2.0

I would like to use FOSUser Bundle 2.0 with symfony 4.0 but in all tutorial on internet there is folder app which I don't have.What i done: Installation of FOSUser Bundle 2.0 via Composer:$ composer require friendsofsymfony/user-bundle "~2.0"And after that I am done because there is required /app folder whith some files which I don't have. Any solutions?...Read more

symfony - How to work on plugin and theme simultaneously in Sylius?

I have created a project using plugin skeleton.Now how can I have a theme working simultaneously with the plugin?I can create a theme bundle or add view under appSylius documentation says -loading order (priority descending):App templates:<Theme>/views (NEW!)app/Resources/viewsBundle templates:<Theme>/<Bundle name>/views (NEW!)app/Resources/<Bundle name>/views<Bundle>/Resources/viewsI can have a theme bundle registered and work simultaneously with plugin in tests/app/AppKernel.php...Read more

Symfony 3 - render_false form not working

I'm working on a project in Symfony 3, and I have a problem with the render_false.I have to do a dynamic form. Form's fields will depend on the object's values.And there is a lot of possibilities.I do all this treatment on the controller, and I return an array with all the fields I have to display.Then, I display those fields on Twig. But, I don't want to render the rest.So I use the option : {{ form_end(form, {'render_rest': false}) }}But Symfony returns me "Type error: Argument 1 passed to Bill::setEntreeAutomateInput() must be of the typ...Read more

Symfony Forms persist multiple EntityType

I have no problem to persist from ManytoMany(normal) and ManytoOne, however, I don't understand the proper way to persist entity from OnetoMany and ManytoMany(Reversed).Here is an example :ExampleEntity :.../** * @var ArrayCollection $myentities * * @ORM\OneToMany(targetEntity="AppBundle\Entity\Myentity", mappedBy="exampleentity", cascade={"persist"}) */private $myentities;// getters/setters/*public function addMyentity(Myentity $myentitie)public function removeMyentity(Myentity $myentitie)public function getMyentities()public function setMyent...Read more

symfony - Require a field in symfony2 server side

I have a form in Symfony2 which I am building with buildFormI add constraints like so,$builder->add('firstName', 'text', [ 'required' => true, 'constraints' => [ new NotBlank(), ], ])Everything works fine until I delete the input from my html and submit it without the firstName. I don't get any errors and it submits normally. Is there a way to absolutely require the firstName, even if is not present in the submit data...Read more

Symfony 3.4 - Form collection with drop-down list

In my symfony project I have two entity "Conducteur" and "Datevisite" with a one to many relationship.i have a limited number of datevisite between 1 and 3 determined by a drop-down list.the problem is that I insert each time 3 Datevisites even if I only have to insert one and I do not know how to do it.Conducteur entity : class Conducteur{ /** * @var Datevisite * * @ORM\OneToMany(targetEntity="PDF\RegBundle\Entity\Datevisite", mappedBy="fkConducteur", cascade="all") */ private $datevisites; /** * Conducteur constru...Read more

symfony - FOSUserBundle not working Validation

I'm using symfony 3.3 and php 7.0 with the FOSUserBundle version 2.1.1 and I just realize that in the User Entity if you just add in the setters parameters the type hint like for example this... the validation will fail.<?phpnamespace AppBundle\Entity;use ...;/** * @ORM\Entity * @ORM\Table(name="`user`") */class User extends BaseUser{ /** * @Assert\NotBlank() * @var string * @ORM\Column(type="string", nullable=false) */ private $firstName; /** * @return string */ public function getFirstName() { ret...Read more

xmlserializer - How do I add/update xml attributes with Symfony Serializer using my class/object?

I have the following code example which defines a Contact class that can hold a name and a list of phone numbers. What I want to be able to do is set an attribute of "primary" on all the numbers, where the value for it is '1' for one of them arbitrarily, and '0' for the rest.I'd really like to do this using a class method but couldn't find a way to do this using a setter - is it possible somehow? Here's my code. In it I:Create my objects and set their properiesprint_r the Contact object to see how it is stored Deserialize the xml that I'd like ...Read more

xmlserializer - How do I control tag ordering when using Symfony Serialiser to create XML?

I have the following test case but I'm finding that the XML sections don't come out in the order I require. The SOAP API i'm using issued this message:<Search Type="Error"> <ErrorCode>150</ErrorCode> <ErrorMessage>Invalid Entry : Invalid content was found starting with element &apos;Telephones&apos;. One of &apos;{Addresses}&apos; is expected. </ErrorMessage></Search If I edit the XML and submit it with Address first, everyone is happy.So I need the Address tag to precede the Numbers tag. W...Read more

How to use Symfony Serializer on a nested object with multiple instances of child?

Using the simple example below, how do I update it to handle multiple contact numbers?<?php/*** Symfony Serializer experiment */require $_SERVER['DOCUMENT_ROOT'].'/libraries/symfony/vendor/autoload.php';use Symfony\Component\Serializer\Serializer;use Symfony\Component\Serializer\Encoder\XmlEncoder;use Symfony\Component\Serializer\Encoder\JsonEncoder;use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;class Contact{ private $name; private $number; // Getters p...Read more