0

I have a class Type:

class CandidatType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('prenom', TextType::class)
            ->add('nom', TextType::class)
            ->add('email', EmailType::class)
            ->add('telephone', TelType::class)
...

And I want to show in Twig just the attribute email for example

So how to do that?

In twig I have done this:

{{ form_start(form) }}
    <div class="">
        {{ form_errors(form) }}
    </div>

    <div class="row">
        <div class="col">
            {{ form_row(form.email) }}
        </div>
    </div>
{{ form_end(form) }}

But it shows all the form :/ I need only email

Jakub Matczak
  • 15,341
  • 5
  • 46
  • 64
Khalil
  • 288
  • 3
  • 16
  • `{{ form_end(form, {'render_rest': false}) }}` https://symfony.com/doc/current/form/form_customization.html#form-end-form-view-variables – Fabian Schmick Mar 12 '19 at 13:45
  • 3
    Possible duplicate of [How to make form\_rest() not display a field with Symfony2?](https://stackoverflow.com/questions/10570002/how-to-make-form-rest-not-display-a-field-with-symfony2) – Fabian Schmick Mar 12 '19 at 13:48
  • Ok thank you, can i add a form not existe in class ? – Khalil Mar 12 '19 at 13:57
  • 1
    if you mean to add form fields in the template, yes you can, but it might cause problems and/or extra code to handle it. also, please don't ask questions that extend the original question in comments, because it defeats the purpose of the site. – Jakumi Mar 12 '19 at 14:05
  • @Fabian, i have added render_rest : false, but when i submit, i see this error The CSRF token is invalid. Please try to resubmit the form – Khalil Mar 12 '19 at 14:59
  • @Khali please read the answers from my referneced question. You have to render the token, too. – Fabian Schmick Mar 12 '19 at 15:01
  • thank you, i have added {{ form_row(form._token) }} – Khalil Mar 12 '19 at 15:02

0 Answers0