Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8139005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:41:16+00:00 2026-06-06T11:41:16+00:00

Trying to customize Symfony2 form to produce html code looking like the following example:

  • 0

Trying to customize Symfony2 form to produce html code looking like the following example:

<div class="cform_box">
  <div><label>First name:</label></div>
  <input name="" type="text" id="" class="TextBox" />
</div>
<div class="cform_box" style="height:auto">
   <div><label>Message:</label></div>
  <textarea name="" rows="10" cols="38" id="" class="TextBox" style="height:100px;" /></textarea>
</div>

My form code :

$builder->add('name', 'text', array('label' =>'First Name:'));
$builder->add('message', 'textarea', array('label' =>'Message:'));

The template contact.html.twig:

{% form_theme form _self %}
{% block text_widget %}
{% spaceless %}
    <input type="text" class='TextBox' {% if value is not empty %}value="{{ value }}"     {% endif %}/>
{% endspaceless %}
{% endblock %}
{% block textarea_widget %}
{% spaceless %}
    <div class="textarea_widget">
        <textarea rows="10" cols="38" id="{{ id }}" class="TextBox" style="height:100px;">{{ value }}</textarea>
    </div>
{% endspaceless %}
{% endblock textarea_widget %}

<div class="cform_box">    
    <div>{{ form_label(form.name) }}</div>{{ form_widget(form.name) }}
</div>
<div class="cform_box" style="height:auto">
    <div>{{ form_label(form.message) }}</div>{{ form_widget(form.message) }}
</div>

I am getting either Variable "value" does not exist in contact.html.twig or Variable "id" does not exist in form_div_layout.html.twig if I comment {% block text_widget %} out.

I’m using Symfony 2.0.15

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:41:18+00:00Added an answer on June 6, 2026 at 11:41 am

    The block named ‘text_widget’ does not exist in Symfony2 forms helpers. It’s a field_widget with type = 'text'.

    You should add class “textBox” from your php Form definition, with ‘attr’ :

    $builder->add('name', 'text', array('label' =>'First Name:', 'attr' => array('class' => 'textBox')));
    $builder->add('message', 'textarea', array('label' =>'Message:', 'attr' => array('class' => 'textBox')));
    

    Or in your form_theme file :

    {% block field_widget %}
    {% spaceless %}
        {% if type == 'text' or type == 'textarea' %}
            {% set attr = attr|merge({'class': attr.class|default('') ~ ' textBox'}) %}
        {% endif %}
        {% set type = type|default('text') %}
        <input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" />
    {% endspaceless %}
    {% endblock field_widget %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to customize the font of a UITableViewCell using the following code
Using the guide http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html i'm trying to customize error message, but i've a problem:
I am trying to customize Django's comments form. Inside django.contrib.comments.forms I noticed that all
I'm trying to customize the Liferay Web Form portlet to accept file upload, and
I'm tring to customize error rendering in my form according to this example .
I am trying to customize an Ext.form.Slider in Sencha Touch 1.1. This is my
I'm trying to customize my admin panel. I have copied change_list.html to the proper
I'm new to PHP and trying to customize the following PHP line on my
I am trying to customize date from my RSS feed to display like how
I am trying to customize the DispForm.aspx Display form in an announcement list but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.