Taieb Baccouche
Taieb Baccouche

Reputation: 217

how to change input type from twig

I am new to symfony2. I'm using the 2.3 version of Symfony with twig 1.0.

My problem is that I'am trying to change the input field type from text to email.

Here is my code:

<div class="control-group">
    {{ form_label(form.generalEmail, null, {'label_attr': {'class': 'control-label'}}) }}
    {{ form_errors(form.generalEmail) }}
    <div class="controls">
        <div class="span12">
            {{ form_widget(form.generalEmail, {'attr': {'class': 'span6'}}) }}
        </div>
    </div>
 </div>

how can I do that?

Upvotes: 2

Views: 2345

Answers (2)

BENARD Patrick
BENARD Patrick

Reputation: 30975

I think you should edit your form builder.

Your current field in builder is 'text', and you should change it to 'email'.

Look at this section of the documentation, it's the best doc source :

Upvotes: 1

Jon Winstanley
Jon Winstanley

Reputation: 23311

Symfony tries to figure out what type of form field is most appropriate based on your entity file.

In your form, an input field is shown because your entity field type is string. In your form builder there is probably this:

$builder->add('email');

Change it to specify that you want an email field.

$builder->add('email', 'email');

Upvotes: 2

Related Questions