Как я могу использовать тег HTML5 <button>в Drupal 6 - PullRequest
1 голос
/ 19 декабря 2010

У меня есть следующий 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 Ответ

1 голос
/ 01 января 2011

drupal напрямую не поддерживает элемент

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.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...