duaeim2874
2013-06-07 22:07
浏览 65
已采纳

Symfony2表单生成器 - 删除标签,使其占位符

I am playing with Symfony's form builder, and I can't find a way to not display a label. Further, I am interested in actually setting a placeholder for each input box. Is this possible? I have researched a bit and found nothing.

My form:

<form action="{{ path('searchPeople') }}" method="post" class="form-inline">
    {{ form_errors(form) }}

    {{ form_row(form.first_name) }}
    {{ form_row(form.last_name) }}

    {{ form_rest(form) }}

    <br />
    <button type="submit" class="btn btn-primary" /><i class="icon-search"></i>Search</button>
</form>

EDIT: Solved! All of the solutions below helped, but I gave the answer to the primary helpful comment. I appreciate all of the help. For anyone else that comes across this, this is my final working code:

<form action="{{ path('searchPeople') }}" method="post" class="form-inline">
    {{ form_errors(form) }}

    {{ form_errors(form.first_name) }}
    {{ form_widget(form.first_name, {'attr': {'placeholder': 'First Name'} }) }}

    {{ form_errors(form.last_name) }}
    {{ form_widget(form.last_name, {'attr': {'placeholder': 'Last Name'} }) }}

    {{ form_rest(form) }}

    <br />
    <button type="submit" class="btn btn-primary" /><i class="icon-search icon-white"></i>Search</button>
</form>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

12条回答 默认 最新

  • dongtaijiao7140 2013-06-07 22:11
    已采纳

    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, '') }}
    
    评论
    解决 无用
    打赏 举报
查看更多回答(11条)

相关推荐 更多相似问题