I have my search environment set up, works great, delivers just the results I expect. My only issue is I just want users to use the Enviroment to search one specific cck field. I would like to disable the Anywhere keyword search.

If possible, I would also like to remove the "More Options" on the search environment block, take out the drop down options on the search environment page, and maybe even change the text on the "Search" button. Basically, for this particular site, strip the users' search options way down.

It says here that this may be possible with hook_form_alter(), but although I have been checking out the module code and reading the api docs, I still have no idea where to begin. If someone could nudge me in the right direction, that would be awesome.

Comments

drpl’s picture

[env] is the environment id you created, don't forgive to change it in all code below

In template.php

  function YOURTHEMENAME_theme(){
  return array(
     'faceted_search_ui_form_[env]' => array(
      'arguments' => array('form' => NULL,),
      'template' => 'faceted_search_ui_form_[env]',
    ),

  );
}

function YOURTHEMENAME_preprocess_faceted_search_ui_form_[env](&$vars) {
  // That's where $form_markup is created


   $vars['form']['refine']['#access'] = False;
   $vars['form']['keywords']['#size'] = 10;
   $vars['form']['keywords']['#attributes'] = array("class" => "se_c");
   $vars['form_keywords'] = drupal_render($vars['form']['keywords']);
   /////

    $vars['form']['submit']['#attributes'] = array("class" => "bt_se");
    $vars['form']['submit']['#value'] = "";
    $vars['form_submit'] = drupal_render($vars['form']['submit']);



    $vars['form']['go-select']['#value'] = '';

  


  // passing the form to the template
  $vars['form_markup'] = drupal_render($vars['form']);

}

and after that make theme file called faceted_search_ui_form_[env].tpl.php

<?php print $form_markup;?>
<?php print $form_keywords;?>
<?php print $form_submit;?>

Abdulla
bamlhs@hotmail.com

jenna.tollerson’s picture

Well, I must be doing this wrong, because it doesn't seem to have any effect. Here's my code in template.php:

 function camizio_theme(){
  return array(
    'faceted_search_ui_form_2' => array(
      'arguments' => array('form' => NULL,),
      'template' => 'faceted_search_ui_form_2',
    ),
  );
}

function camizio_faceted_search_ui_form_2(&$vars) {
  // That's where $form_markup is created

  $vars['form']['refine']['#access'] = False;
  $vars['form']['keywords']['#size'] = 10;
  $vars['form']['keywords']['#attributes'] = array("class" => "se_c");
  $vars['form_keywords'] = drupal_render($vars['form']['keywords']);
  /////

  $vars['form']['submit']['#attributes'] = array("class" => "bt_se");
  $vars['form']['submit']['#value'] = "";
  $vars['form_submit'] = drupal_render($vars['form']['submit']);

  $vars['form']['go-select']['#value'] = '';

  // passing the form to the template
  $vars['form_markup'] = drupal_render($vars['form']);
} 

Then of course I have a file called faceted_search_ui_form_2.tpl.php with the text specified above. But when I go look at my search page or block, everything is exactly the same. Am I implementing this right?

drpl’s picture

I was tested my code above and it work so fine

you have first at all run corn, and go to admin/build/themes

i hope it's work with u

jenna.tollerson’s picture

Which version of the module are you using?

drpl’s picture

6.x-1.x-dev

jenna.tollerson’s picture

That must be why the code isn't working for me. I'm using 5.x-1.0-beta4. Hmmm. I wonder if there is a way to backport this.

jenna.tollerson’s picture

Status: Active » Fixed

So I figured out what I needed to do, and it was definitely to use hook_form_alter(). I think this solution is very specific to my case, but I'm posting this here in case it is helpful to someone else.

I was helped by a short tutorial on hook_form_alter() here on Ubercart.org forums, which cleared up for me exactly what I'm supposed to do with that function. I created a small module called rrforms, and in rrforms.module I used this code:

 function rrforms_form_alter($form_id, &$form) {
  if($form_id == 'faceted_search_ui_form') {
    $form['go-select']['#value'] = NULL;
    $form['refine'] = false;
    $form['operator']['#type'] = 'hidden';
    $form['operator']['#default_value'] = 'and';
  }
} 

This is probably kind of hacky but it gave me what I wanted. I did put the following code in my template.php to change the fieldset legend on the search enviroment page, but this was the only change to my theme.

 function mythemename_faceted_search_ui_stage_select($search, $keyword_block_content, $guided_block_content) {
  if ($keyword_block_content) {
    $form['keyword'] = array(
      '#type' => 'fieldset',
      '#title' => t('My new instruction text'), // change is here
      '#value' => $keyword_block_content,
      '#weight' => 0,
      '#attributes' => array('class' => 'faceted-search-keyword'),
    );
  }
  if ($guided_block_content) {
    $form['guided'] = array(
      '#type' => 'fieldset',
      '#title' => t('Guided search'),
      '#value' => $guided_block_content,
      '#weight' => 1,
      '#attributes' => array('class' => 'faceted-search-guided'),
    );
  }
  return drupal_render($form);
} 

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

robmil29’s picture

After applying the code in #1 my block is themed how it should be. However, now when I click submit it takes me back to the home page. The same thing goes for the 'more options' link. Does anyone know why this might be? I have the code copied exactly as is.