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和/或类来进行样式设置.

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些