Symfony : CreateForm / Why my textarea do not appear?

I have a problem to display a textarea from a form I’ve created with Symfony.

The textarea appears in html but it has no display: block in the css. It has nothing in the css, to be clear.

When I add a display:block in the css myself, it simply stripped by chrome/firefox.

The problem only happens when I create the form from a separate Class, not when I create it in controller’s function.

Here is my code:

AdController.php

<?php

namespace AppController;


use AppEntityAd;
use AppFormAdType;
use AppRepositoryAdRepository;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;
use SymfonyBundleFrameworkBundleControllerAbstractController;

class AdController extends AbstractController
{


    /**
     * Create ad
     *
     * @Route("/ads/new", name="ads_create")
     * 
     * @return Response
     */
    public function create(){

         $ad = new Ad();

         $form = $this->createForm(AdType::class, $ad);


        return $this->render('ad/new.html.twig', [
            'form' => $form->createView()
        ]);
    }


}

AdType.php

<?php

namespace AppForm;

use AppEntityAd;
use SymfonyComponentFormAbstractType;
use SymfonyComponentFormFormBuilderInterface;
use SymfonyComponentOptionsResolverOptionsResolver;
use SymfonyComponentFormExtensionCoreTypeTextareaType;

class AdType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('title')
            ->add('slug')
            ->add('price')
            ->add('introduction')
            ->add('content', TextareaType::class, [
                'attr' => array('cols' => '5', 'rows' => '5')])
            ->add('coverImage')
            ->add('rooms')
        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => Ad::class,
        ]);
    }
}

And twig :

{% extends 'base.html.twig' %}
{% form_theme form 'bootstrap_4_layout.html.twig' %}

{% block title %}Create ad{% endblock %}

{% block body %}
    <div class="container">
        <h1>lorem ipsum</h1>


        {{form_start(form)}}

            {{ form(form) }}



        {{form_end(form)}}

    </div>
{% endblock %}

I tried a lot of things but I still don’t understand how to solve this problem. Do someone have an idea about it ?

Thanks in advance !

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *