PHP 在Drupal 6中自定义块搜索表单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 在Drupal 6中自定义块搜索表单相关的知识,希望对你有一定的参考价值。

function yourtheme_preprocess_search_block_form(&$vars, $hook) {
	// Modify elements of the search form
	unset($vars['form']['search_block_form']['#title']);

	// Set a default value for the search box
  $vars['form']['search_block_form']['#value'] = t('Search this site');
	
	// Add a custom class to the search box
	// Set yourtheme.css > #search-block-form .form-text { color: #888888; }
  $vars['form']['search_block_form']['#attributes'] = array(
  	 'onblur' => "if (this.value == '') {this.value = '".$vars['form']['search_block_form']['#value']."';} this.style.color = '#000000';", 
		 'onfocus' => "if (this.value == '".$vars['form']['search_block_form']['#value']."') {this.value = '';} this.style.color = '#000000';" );

	// Modify elements of the submit button
	unset($vars['form']['submit']);

	// Change text on the submit button
	//$vars['form']['submit']['#value'] = t('Go!');

	// Change submit button into image button - NOTE: '#src' leading '/' automatically added
	$vars['form']['submit']['image_button'] = array('#type' => 'image_button', '#src' => 'sites/all/themes/yourtheme/images/search-button.png');

	// Rebuild the rendered version (search form only, rest remains unchanged)
  unset($vars['form']['search_block_form']['#printed']);
  $vars['search']['search_block_form'] = drupal_render($vars['form']['search_block_form']);

	// Rebuild the rendered version (submit button, rest remains unchanged)
	unset($vars['form']['submit']['#printed']);
	$vars['search']['submit'] = drupal_render($vars['form']['submit']);
	
	// Collect all form elements to print entire form
  $vars['search_form'] = implode($vars['search']);
}

以上是关于PHP 在Drupal 6中自定义块搜索表单的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Drupal 视图块中自定义 HTML 结构

Drupal 6 中的自定义搜索表单:视图/面板还是自定义 sql?

PHP Drupal 6自定义登录块

当自定义模板已应用于节点的内容类型时,如何在 Drupal 6 中自定义特定节点?

如何在 Drupal 8 中自定义/样式/主题自定义内容类型的输出?

PHP 删除Drupal的搜索块“搜索此站点”标签。