symfony-forms

Symfony Generator Forms, Doctrine, and M:N Relationships

不想你离开。 提交于 2019-12-02 09:59:14
I have a basic M:N setup with three tables: candidate, position, and candidate_position. Here's a screenshot of the ERD from MySQL Workbench Now, moving on from that let's talk about forms. In the default world of symfony generator, you'd have a separate CRUD interface for all three of these tables. However, I don't want to have a CRUD interface for candidate_position . What I want, is for the create and edit actions of the Candidate interface to contain a multi-choice field (select list, checkbox array, whatever) that would create the CandidatePosition records as part of the Candidate actions

Symfony 3 - Form model data loses property values which are not represented by fields

大憨熊 提交于 2019-12-02 04:47:14
I have a controller action method which should handle a two-splitted form. Each form handles just a few properties of my Entity Workflow . After submitting the first form I can create and render the second form without problems. Now the problem: After submitting the second form, the information of all values set in the first form are gone which means that when calling submit (or handleRequest does not make any difference here) the entity object only holds data of the properties set in the first form and it even can´t resolve some values properly. Here is the Controller (with some comments):

Symfony2 data transformers, getting exception message

ⅰ亾dé卋堺 提交于 2019-12-02 04:15:36
问题 I've created my own data transformer, as explained in the dedicated cookbook, here is my reverse transformation: public function reverseTransform($val) { // ... // My logic here // ... // If $val is not valid throw new TransformationFailedException( 'My custom error message' ); } The question is: how do I get the "custom error message" thrown? I would like to display it as the error message of my form field. How do I do that? Thanks! 回答1: Sort answer is: You don't. The transformers job is to,

Symfony2 data transformers, getting exception message

江枫思渺然 提交于 2019-12-02 01:34:21
I've created my own data transformer, as explained in the dedicated cookbook , here is my reverse transformation: public function reverseTransform($val) { // ... // My logic here // ... // If $val is not valid throw new TransformationFailedException( 'My custom error message' ); } The question is: how do I get the "custom error message" thrown? I would like to display it as the error message of my form field. How do I do that? Thanks! Sort answer is: You don't. The transformers job is to, well, transform and not to do error checking. Add a constraint to the field which will check the

Symfony get form data in controller

喜你入骨 提交于 2019-12-01 17:26:00
问题 I have this view: //login.html.twig <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MY APP</title> </head> <body> <form action="{{ path('conection') }}" method="post" name="formulario_login"> <label for="username">User:</label> <input type="text" id="username" name="_username" value="{{ last_username|default('') }}" /> <br /> <label for="password">Password:</label> <input type="password" id="password" name="_password" /> <br /> <input

Symfony get form data in controller

孤人 提交于 2019-12-01 17:15:26
I have this view: //login.html.twig <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MY APP</title> </head> <body> <form action="{{ path('conection') }}" method="post" name="formulario_login"> <label for="username">User:</label> <input type="text" id="username" name="_username" value="{{ last_username|default('') }}" /> <br /> <label for="password">Password:</label> <input type="password" id="password" name="_password" /> <br /> <input type="checkbox" id="remember_me" name="_remember_me"/> <label for="remember_me">Remember me</label>

How to override Symfony form MoneyType input as type=“number”?

∥☆過路亽.° 提交于 2019-12-01 17:03:00
The Symfony MoneyType Field renders as input type="text" which allows a user to type whatever they want into the field. How can I override this to render as input type="number" so that users can only enter numeric characters? $formBuilder->add("amount", MoneyType::class, [ 'currency' => 'USD' ]); Current output: <div><label for="form_amount" class="required">Amount</label>$ <input type="text" id="form_amount" name="form[amount]" required="required" /></div> What I am trying to achieve: <div><label for="form_amount" class="required">Amount</label>$ <input type="number" id="form_amount" name=

Optional embed form in Symfony 2

让人想犯罪 __ 提交于 2019-12-01 12:21:20
I have two entities in my system: Person and Phone as the following code. class Person { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\Column(type="string", length=100) */ private $name; /** * @ORM\Column(type="string", length=100) */ private $lastName; /** * @ORM\OneToOne(targetEntity="Phone", cascade={"persist"}) */ private $phone; }; class Phone { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\ManyToOne(targetEntity="PhoneType") */ private $type; /** * @ORM\Column

Optional embed form in Symfony 2

核能气质少年 提交于 2019-12-01 09:47:03
问题 I have two entities in my system: Person and Phone as the following code. class Person { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\Column(type="string", length=100) */ private $name; /** * @ORM\Column(type="string", length=100) */ private $lastName; /** * @ORM\OneToOne(targetEntity="Phone", cascade={"persist"}) */ private $phone; }; class Phone { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO

Define a form option allowed values depending on another option value in a FormType

你离开我真会死。 提交于 2019-12-01 09:16:56
In Symfony 2.8, in a custom form type, is it possible to make setAllowedValues return a result that depends on the value of another option? There isn't an obvious way to access an Options object in the closure as far as I can see. public function configureOptions(OptionsResolver $resolver) { $resolver->setRequired('option1'); $resolver->setRequired('option2'); $resolver->setAllowedValues('option2', function ($value) { return $based_on_set_restricted_by_option1; // <-- option2 values are allowed or denied depending on what option1 says } } The closest idea to a solution that I have is to have