Symfony2 Form Builder - Remove label, make it placeholder

Convert label to placeholder

{% use 'form_div_layout.html.twig' with widget_attributes as base_widget_attributes %}
{% block widget_attributes %}
    {% set attr = {'placeholder': label|trans({}, translation_domain)} %}
    {{- block('base_widget_attributes') -}}
{% endblock widget_attributes %}

I know it's already answered, but might help somebody who is looking for a different solution for placeholders, if you don't want to change anything in your twig template:

$builder->add(
    'name',
    'text', 
     array(
        'attr' => array(
             'placeholder' => 'Your name',
        ),
        'label' => false,
     )
);

If you're outputting the field with form_rest you'll have to set the label for the the field to false in the form builder with something like

$builder->add('first_name', 'text', array(
    'label' => false,
));

If you output the fields individually, you can omit the form_label for that field in the twig template, or set it to an empty string.

{{ form_label(form.first_name, '') }}

Tags:

Php

Symfony