Drupal - 用 div 包围特定的 Web 表单元素
正如标题所描述的,我要设计一个网络表单,为此我需要包围 div 中的特定字段,以便为它们提供 CSS 属性,但我不知道应该如何去做。
我已经用 hook_form_alter 捕获了表单,但不知道之后要做什么。
有什么帮助吗?
as the title describes, I am to style a webform and for that i need to surround specific fields in divs in order to give them their CSS properties and I have no idea how I should go about doing that.
I've caught the form with hook_form_alter but no idea what to do after.
Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的主题 template.php 文件中,您需要获取表单 ID,然后您可以执行如下操作:
将 FORM_ID 替换为您的表单 ID。
编辑
要为特定字段添加它们,只需执行以下操作(类似):
我没有时间测试它,但将 ELEMENT_NAME 替换为该元素,这应该可以解决您的问题。这里有一个很好的页面 - http://drupal.org/node/79086
In your themes template.php file you need to get the forms ID and then you can do something like the following:
Replace FORM_ID with your form's ID.
EDIT
To add them for specific fields just do (something like) this:
I've not got time to test it but replace ELEMENT_NAME with the element and that should solve your problem. There's a good page on it here - http://drupal.org/node/79086
您可以使用 #field_prefix 和 #field_suffix 将字段与任何 HTML 元素一起包装。请参阅下面的示例:
让我知道你进展如何......
You can use #field_prefix and #field_suffix to wrap field with any HTML element. See example below:
Let me know how you go...
另外:如果您想将包含的 div 添加到网络表单的提交按钮,这里有一个钩子可以帮助您:
如果您想将其应用于所有网络表单,您只需保留条件即可,如下所示:
Additionally: in case you want to add containing div's to the submit button of the webform, here's a hook which will help you out:
If you want to apply this to all webforms, you just leave the conditional away, like this: