【发布时间】:2017-07-05 20:33:09
【问题描述】:
我是 Drupal 的新手。我开发了一个网站。但是在 WCAG 2.0 测试中,我遇到了以下问题:元素“表单”不需要“角色”属性。我如何实现这一点?请帮忙...
谢谢。
这是我的源代码: enter image description here
【问题讨论】:
我是 Drupal 的新手。我开发了一个网站。但是在 WCAG 2.0 测试中,我遇到了以下问题:元素“表单”不需要“角色”属性。我如何实现这一点?请帮忙...
谢谢。
这是我的源代码: enter image description here
【问题讨论】:
您可以使用hook_form_alter 来做到这一点。您需要使用您的自定义模块尝试此代码。
function hook_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'search_block_form') {
$form["#attributes"]["role"] = "";
//Or
unset($form["#attributes"]["role"]);
}
}
您需要在 'sites/all/modules' 目录中创建一个自定义模块,并在 .module 文件中编写此函数,将钩子替换为模块名称。
例如,创建一个名为 custom 的自定义模块。如果需要帮助,请参阅this article。在模块的 custom.module 文件中编写以下函数:
function custom_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'search_block_form') {
$form["#attributes"]["role"] = "";
//Or
unset($form["#attributes"]["role"]);
}
}
希望有帮助!
【讨论】: