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条)

报告相同问题?

悬赏问题

  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程