Drupal:将 id 添加到错误列表
有没有办法将 id 添加到默认的 drupal 错误列表项中?
目前我得到了这个:
<div class="messages error" id="inline-messages">
<ul>
<li>Name is required.</li>
<li>Email is required.</li>
<li>Message is required.</li>
</ul>
</div>
但我想将字段名作为ID:
<div class="messages error" id="inline-messages">
<ul>
<li id="form-field-name">Name is required.</li>
<li id="form-field-email">Email is required.</li>
<li id="form-field-message">Message is required.</li>
</ul>
</div>
正在使用的插件:http://drupal.org/project/inline_messages
有什么建议吗?
Is there a solution to add an id to the default drupal error list items?
Currently i got this:
<div class="messages error" id="inline-messages">
<ul>
<li>Name is required.</li>
<li>Email is required.</li>
<li>Message is required.</li>
</ul>
</div>
But i would like to have the fieldname as id:
<div class="messages error" id="inline-messages">
<ul>
<li id="form-field-name">Name is required.</li>
<li id="form-field-email">Email is required.</li>
<li id="form-field-message">Message is required.</li>
</ul>
</div>
Plugins in use: http://drupal.org/project/inline_messages
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有点晚了,但也许它仍然会帮助您或其他人寻找这个,这些消息的主题为 theme_status_messages() 但此时您没有任何关于它们的上下文。但是...
表单错误是通过 form_set_error() 添加的,根据表单字段名称将它们存储在静态数组中,您可以通过 form_get_errors()。
现在,您可以加载这些错误,然后在该错误数组中查找错误消息并使用键作为 id。
A bit late, but maybe it will still help you or someone else looking for this, the messages are themed in theme_status_messages() but you don't have any context about them at this point. However...
Form errors are added through form_set_error(), which stores them in an static array according to the form field name, you can access that through form_get_errors().
Now, you can load these errors and then look up the error messages in that error array and use the key as the id.