PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 6, 2022

[FIXED] formbuilder choose to not show a field in symfony

 February 06, 2022     php, symfony, symfony-3.4     No comments   

Issue

I'm building a questionnaire that is shown in two templates but I need to not show some filed in one of the templates

 $builder
            ->add('acceptConsent', CheckboxType::class, [
                'label_attr' => [
                    'class' => 'font-weight-bold'
                ],
                'required' => true,
                'constraints' => new NotBlank(),
                'disabled' => $readOnly,
            ])

there is any way to set the form to not render a field?


Solution

You may "just" not render your form_row or form_widget

And close your form this way {{ form_end(form, {'render_rest': false}) }}

So that unrendered fields a not rendered.

Have a look here for more infos: https://symfony.com/doc/current/form/form_customization.html



Answered By - Gregoire Ducharme
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing