微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

forms – Symfony2 / Twig中的表单标记属性

当我想为symfony2表单元素添加一些属性时,我可以使用“attr”属性.但是我如何给起始表单标签本身提供一些id / class / style / other?

解决方法

{{ form_widget(form.name,{ 'attr': {'class': 'foo'} }) }}

这是具有类foo的表单窗口小部件的正确语法.换句话说,表单中的表单字段.

您可以对< form>应用相同的内容.标签.

这是通过渲染完成的

{{ form_start(form,{ 'attr': {'class': 'foo','id': 'bar',... } }) }}

请参阅form_start here上的这篇简短文档

Renders the start tag of a form. This helper takes care of printing the configured method and target action of the form. It will also include the correct enctype property if the form contains upload fields.

您可能还对表单变量感兴趣.它们记录在here中.总而言之,有关于您可以使用的所有函数和变量的完整文档here

我不建议你使用内联样式.只需使用您提供表单的ID和/或类来进行样式设置.

原文地址:https://www.jb51.cc/html/226055.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐