symfony-forms

Add custom options to symfony form

倖福魔咒の 提交于 2021-02-19 01:41:26
问题 1 What i want to do is add custom (option is 'angular' in this case)option to my form widget template: {%- block widget_attributes -%} id="{{ id }}" name="{{ full_name }}" {%- if angular %} ng-model="{{ full_name }}"{% endif -%} .... {%- if intention %} {{ intention }}{% endif -%} {%- if read_only %} readonly="readonly"{% endif -%} ..... {%- endblock widget_attributes -%} I wand to decide about form has it option or no in my CustomFormType. But i can't achieve it. I tried different method. Is

Symfony form differences between row and widget

我的未来我决定 提交于 2021-02-07 11:15:33
问题 What is the differences between form_widget and form_row ? I know that in form_row i can add label in attributes, and form_widget render all fields. are there others difference? 回答1: From documentation: form_widget Renders the HTML widget of a given field. If you apply this to an entire form or collection of fields, each underlying form row will be rendered. form_row Renders the "row" of a given field, which is the combination of the field's label, errors and widget. So main difference is

Symfony form differences between row and widget

非 Y 不嫁゛ 提交于 2021-02-07 11:06:58
问题 What is the differences between form_widget and form_row ? I know that in form_row i can add label in attributes, and form_widget render all fields. are there others difference? 回答1: From documentation: form_widget Renders the HTML widget of a given field. If you apply this to an entire form or collection of fields, each underlying form row will be rendered. form_row Renders the "row" of a given field, which is the combination of the field's label, errors and widget. So main difference is

Calls to isSumbitted() and isValid() result in “undefined method” error

这一生的挚爱 提交于 2021-02-05 12:26:08
问题 I have a Symfony form that is created from createFormBuilder() in the controller. But under two IF statements the form should carry two different set of fields. My Symfony version is 3.4. /src/AppBundle/Controller/DefaultController.php Ex: This is the basic form. $form = $this->createFormBuilder() ->add('name', TextType::class, ['required' => true]]) ->add('email', EmailType::class, ['required' => true]]) ->getForm(); if ($form->isSubmitted() && $form->isValid()) { ... ... ... } Now I need to

'Twig_Error_Syntax' with message Unknown “form_start” function

蹲街弑〆低调 提交于 2021-01-27 11:44:53
问题 Is it possible to make a standalone form with symfony3 and twig? I can't get past this error: Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'Unknown "form_start" function in "new.html.twig" at line 1 The 3.1 documentation cites this example, which works fine, but it's actually using 2.7 My simple project is organized like this: . ├── composer.json ├── composer.lock ├── src │ └── form.php ├── vendor │ └── ... └── views └── new.html.twig form.php <?php require_once __DIR__.'/

'Twig_Error_Syntax' with message Unknown “form_start” function

僤鯓⒐⒋嵵緔 提交于 2021-01-27 11:42:43
问题 Is it possible to make a standalone form with symfony3 and twig? I can't get past this error: Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'Unknown "form_start" function in "new.html.twig" at line 1 The 3.1 documentation cites this example, which works fine, but it's actually using 2.7 My simple project is organized like this: . ├── composer.json ├── composer.lock ├── src │ └── form.php ├── vendor │ └── ... └── views └── new.html.twig form.php <?php require_once __DIR__.'/

Symfony form validation of decimal field

99封情书 提交于 2020-12-16 07:08:06
问题 I am trying to use the Assert validation rule with decimal and it fails with error. Here is my form $builder->add('cinp_number', 'number', array( 'required' => false, )); Here is my Entity /** * @Assert\Type(type="decimal") * @var decimal */ private $cinp_number; This is the error when submiting form with string value as input: Warning: NumberFormatter::parse(): Number parsing failed LOG Message: request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException:

Symfony 4 - how to add csrf token without building form?

被刻印的时光 ゝ 提交于 2020-12-08 07:13:07
问题 I am reading tutorial here https://symfony.com/doc/current/form/csrf_protection.html how to add csrf token. It says to use form_end() in the template. But this is not working, gives error: Type error: Too few arguments to function Symfony\Component\Form\FormRenderer::renderBlock(), 0 passed in E:\projektai\php projektai\htdocs\mokomieji\symfony_4_demo\var\cache\dev\twig\bb\bb2248f7be504240fcc2ab43dabf593090ebc4c897ce72b1a979082d62914b47.php on line 48 and at least 2 expected Here is answer

Symfony2 invalid form still saves entity on flush

让人想犯罪 __ 提交于 2020-03-18 09:56:14
问题 I currently have a form and on save I always make an API call to validate the form information against an external source (eg: is the company a VAT paying company etc.). I also want to store in the database the response I get from the external API, for which I have a post submit subscriber on the form. In the subscriber, I call the API and set errors on the form where values do not match. That is where I call a service to handle all the business logic and somewhere in there I have $em-

Manually change or catch the message for invalid CSRF token in Symfony2.1

我怕爱的太早我们不能终老 提交于 2020-03-17 07:36:32
问题 I'm using Symfony2.1 . It has a builtin CSRF protection for the forms. The error message returned when the CSRF token is invalid is: " The CSRF token is invalid. Please try to resubmit the form ". I show it on the top of the form in my Twig template by using the classic call: {{ form_errors(form) }} How can I change the returned message? In alternative, a more advanced possibility is to catch this error type in order to show a lot of options/links in my Twig template. Any idea? 回答1: Did you