如何在Drupal 6 </button>中使用HTML5 <button>标签

时间:2010-12-19 18:35:16

标签: drupal search

我有以下HTML,我想在我的Drupal 6主题中使用。它需要替换搜索框代码。

    <fieldset class="search">
        <input type="text" class="box font-myriad" />
        <button class="btn" title="Submit Search">Search</button>
    </fieldset>

我正在尝试像

这样的东西
$vars['form']['button']['#attributes'] = array('class' => 'btn');

在template.php中,但到目前为止还没有运气。在drupal.org上找不到太多帮助。

1 个答案:

答案 0 :(得分:1)

drupal不直接支持HTML5&lt;按钮&gt; element ...因为没有javascript,它没有做太多。如果确实需要它,您可以使用theme_button来覆盖该特定元素。

http://api.drupal.org/api/drupal/includes--form.inc/function/theme_button/6

<?php
function phptemplate_button($element) {
  // Make sure not to overwrite classes.
  if (isset($element['#attributes']['class'])) {
    $element['#attributes']['class'] = 'form-' . $element['#button_type'] . ' ' . $element['#attributes']['class'];
  }
  else {
    $element['#attributes']['class'] = 'form-' . $element['#button_type'];
  }

  if ($element['#button_type'] == 'button') {
    // return a fancy html button.
    return '<button ' . (empty($element['#name']) ? '' : 'name="' . $element['#name'] . '" ') . 'id="' . $element['#id'] . '" ' . drupal_attributes($element['#attributes']) . ">" . check_plain($element['#value']) . "</button>\n";
  } else {
    // retain the normal functionality for anything else
    return '<input type="submit" ' . (empty($element['#name']) ? '' : 'name="' . $element['#name'] . '" ') . 'id="' . $element['#id'] . '" value="' . check_plain($element['#value']) . '" ' . drupal_attributes($element['#attributes']) . " />\n";
  }
}
?>

然后你的代码就是:

$form['content']['search'] = array(
  '#type' => 'submit',
  '#button_type' => 'button',
  '#name' => 'search',
  '#value' => t('Search'),
  '#attributes' => array('class' => 'btn', 'title'=>'Submit Search')
);

应输出:

<button id="edit-search"  class="form-button btn" title="Submit Search" name="search" >Search</button>

在Drupal 6中测试。