Search code examples
symfonytwigformbuilder

Symfony2 FormBuilder isn't rendering text fields


I'm using Symfony's FormBuilder to create a form and render it via Twig.

I use this as my Type:

<?php

namespace Vendor\AppBundle\Form;

use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\AbstractType;

class RequestType extends AbstractType
{

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('name', 'text');
        $builder->add('email', 'email');
        $builder->add('question', 'textarea');

    }

    public function getDefaultOptions(array $options)
    {
        return array('data_class' => 'Vendor\\AppBundle\\App\\Request');
    }

    /**
     * Returns the name of this type.
     *
     * @return string The name of this type
     */
    public function getName()
    {
        return 'request';
    }
}

When I render my form (with form_widget(form.field)) everything looks great, except for the name field, that doesn't output any input field. If I change to something like "email", it works perfectly.

I'm using Sf2.3 BETA 1. Any thoughts on why does this happen with text fields only? It's woth noting that the labels, fieldsets, and everything is outputted, except the actual <input> tag.

EDIT 1: This is the Controller Code, in case you need it.

EDIT 2: It's worth noticing that this is an update from a Sf2.1 app to Sf2.3 BETA 1. The code has been updated, but perhaps something's wrong with that?


Solution

  • In this case, it was something that had to do with the fact that this code is a refactor of really old (+2 years) code.

    The issue was that the form widget was being replaced with another one, and that "other one" was messing with the output, since Twig's functions aren't the same, nor the structure.