[Решено]Темизация поиска D7

Главные вкладки

Аватар пользователя johnworld johnworld 20 ноября 2011 в 1:45

Подскажите, пожалуйста, как правильно затемизировать форму поиска в друпал7?

в файле template.php добавляю код:

<?phpfunction letopis2_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'search_block_form') {
      $form['search_block_form']['#id'] = 'search_bg';
    $form['search_block_form']['#title'] = t('Поиск по сайту'); // Change the text on the label element
    $form['search_block_form']['#title_display'] = 'invisible'; // Toggle label visibilty
    $form['search_block_form']['#size'] = 60;  // define size of the textfield
    $form['search_block_form']['#default_value'] = t('Что ищем?'); // Set a default value for the textfield
    $form['actions']['submit']['#value'] = t('GO!'); // Change the text on the submit button
    $form['actions']['submit'] = array('#type' => 'image_button', '#src' => base_path() . path_to_theme() . '/images/button_s.gif');

// Add extra attributes to the text box
    $form['search_block_form']['#attributes']['onblur'] = "if (this.value == '') {this.value = 'Что ищем?';}";
    $form['search_block_form']['#attributes']['onfocus'] = "if (this.value == 'Что ищем?') {this.value = '';}";
  }
} ?>

Друпал генерит следующий код:

<form action="/" method="post" id="search-block-form" accept-charset="UTF-8">
<div>
   <div class="form-item form-type-textfield form-item-search-block-form">
      <label class="element-invisible" for="search_bg">Поиск по сайту </label>
      <input title="Enter the terms you wish to search for." onblur="if (this.value == &#039;&#039;) {this.value = &#039;Что ищем?&#039;;}" onfocus="if (this.value == &#039;Что ищем?&#039;) {this.value = &#039;&#039;;}" type="text" id="search_bg" name="search_block_form" value="Что ищем?" size="60" maxlength="128" class="form-text" />
   </div>
<div class="form-actions form-wrapper" id="edit-actions">
   <input type="image" id="edit-submit--3" name="submit" src="/sites/all/themes/letopis2/images/button_s.gif" class="form-submit" />
</div>
<input type="hidden" name="form_build_id" value="form-cG-_1SpY_09CxrBgmqOq3f85BgxTStUZGfPFD2YgjPs" />
<input type="hidden" name="form_id" value="search_block_form" />
</div>
</form>

Мне же надо убрать все лишнее, чтобы код выглядел так:

<form action="/" method="post" id="search-block-form" accept-charset="UTF-8">
<label class="element-invisible" for="search_bg">Поиск по сайту </label>
<div id="search_bg">
   <input name="search_block_form" id="search_input" type="text" onblur="if(this.value==&#39;&#39;) this.value=&#39;Что ищем?&#39;" onfocus="if(this.value==&#39;Что ищем?&#39;) this.value=&#39;&#39;" value="Что ищем?">
</div>
<div id="button_s"><input src="<?php echo $directory;?>/images/button_s.gif" alt="Search" type="image" name="submit"></div>
<input type="hidden" name="form_build_id" value="form-cG-_1SpY_09CxrBgmqOq3f85BgxTStUZGfPFD2YgjPs" />
<input type="hidden" name="form_id" value="search_block_form" />
<div class="clr"></div>
 </form>

То есть, каким образом можно выпилить все ненужное и вставить то что нужно. В каком месте это делается, если есть примеры, буду признателен.

Комментарии

Аватар пользователя johnworld johnworld 20 ноября 2011 в 2:04

Убрал все лишнее DIV и классы, сделав так:
в файле search-block-form.tpl.php прописал следующее:

<?php if ($search_form): ?>                           
  <?php print strip_tags (  $search_form '<form><input><label>') ; ?>                           
<?php endif; ?>

теперь выводит чистый код без мусора:

<form action="/" method="post" id="search-block-form" accept-charset="UTF-8">
<div>
<label class="element-invisible" for="search_bg">Поиск по сайту </label>
<input title="Enter the terms you wish to search for." onblur="if (this.value == &#039;&#039;) {this.value = &#039;Что ищем?&#039;;}" onfocus="if (this.value == &#039;Что ищем?&#039;) {this.value = &#039;&#039;;}" type="text" id="search_bg" name="search_block_form" value="Что ищем?" size="60" maxlength="128" class="form-text" />
<input type="image" id="edit-submit" name="submit" src="/sites/all/themes/letopis2/images/button_s.gif" class="form-submit" /><input type="hidden" name="form_build_id" value="form-yLX3oPFOYziNpfPiNNIk09V4gUlxG5G01WYoYndIlAM" />
<input type="hidden" name="form_id" value="search_block_form" />
</div>
</form>

Но вопрос остался, как теперь добавить свои классы в нужное место?