如何从 drupal 的表单标签中删除 role="search"?
How do I remove role="search" from the form-tag in drupal?
我是 Drupal 新手。我开发了一个站点。但是在 WCAG 2.0 测试中我遇到了以下问题:Element 'form' does not need a 'role' attribute. 我如何实现这个?请帮助...
谢谢。
这是我的源代码:
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"]);
}
}
希望对您有所帮助!
我是 Drupal 新手。我开发了一个站点。但是在 WCAG 2.0 测试中我遇到了以下问题:Element 'form' does not need a 'role' attribute. 我如何实现这个?请帮助...
谢谢。
这是我的源代码: 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"]);
}
}
希望对您有所帮助!