Project:Faceted Search
Version:6.x-1.0-beta2
Component:General
Category:support request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Hi, I've been trying to theme/alter the block 'Keyword search' (faceted_search_ui_form) but seems like there's no easy way to do it. Can somebody point me into the right direction please?

Thanks in advance.

Comments

#1

Status:active» fixed

I found the solution at: http://drupal.org/node/406544

Here it is using hook_form_alter. In my case, I just wanted to change the order of things, specially the submit button, this way I could use css to float the button next to the search box..

My module is facetedalter..

function facetedalter_form_alter(&$form, $form_state, $form_id) {
  // uncomment the line below to found out what form id your using
  // print $form_id;

  if($form_id == 'faceted_search_ui_form_1') {
    $form['operator']['#type'] = 'hidden';
    $form['operator']['#default_value'] = 'and';
    $form['submit']['#type'] = 'submit';
    $form['submit']['#value'] = t("Go!");
    $form['keywords']['#default_value'] = t("Search here");
    $form['keywords']['#attributes'] = array('onblur' => "if (this.value == '') {this.value = '". t("Search here") ."';}", 'onfocus' => "if (this.value == '". t("Search here") ."') {this.value = '';}" );

    // $form['refine']['#title'] = t("Search within results");
    $form['refine'] = FALSE; // comment this line and uncomment the line above to show the checkbox "Search within results"
    // $form['refine']['#attributes'] = array("class" => "withinresults"); // in case you want some extra attributes
    $form['go-select']['#value'] = ''; //comment this line and uncomment the line below to show the "More options" link
    // $form['go-select']['#value'] = l(t('More options'), $path, array('attributes' => array('class' => 'faceted-search-more')));
  }
}

Don't forget to clear the cache.

I found another way to do this using preprocess functions but I think this way is easier.

#2

Status:fixed» closed (fixed)

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

#3

lelizondob,

That's a great tip above - thanks mate.

Just a quick question: is it possible to get it so that the 'Search here...' text disappears when you click on the box?

#4

ha. just found it... remove the "..." in the default_value line and you're away.

Thanks again mate

#5

@peashooter: the default value needs to be exactly the same as the value you're hiding with javascript.. I have a small mistake in the code in #1, I'm going to edit it now.

#6

Status:closed (fixed)» active

In my case, I just wanted to change the order of things, specially the submit button, this way I could use css to float the button next to the search box.

Hey lelizondob,

This is exactly what I'm trying to do, but I'm not able to work out how I should restructure the form array so the submit button appears within the same div as the textfield... Is there something I'm missing in the code above?

Would you (or anyone who knows) mind adding an example of how to do this?

Cheers!

#7

You'll have to reconstruct the entire form, not only changing some of it's values like I did, find the form in the module, copy it and then change it to your needs, I think it should work. You could also try adding some jquery to do what you want.

#8

Yeah, I'm tempted by the jquery route, but fixing something at the client end kinda irks me :)

Cheers for the advice, I'll hunt for where the form is constructed in the module. (I'm still trying to get my head around the forms API, to be honest)

Thanks again.

#9

Okay, so I've identified that the construction function is faceted_search_ui.module:faceted_search_ui_form.

I'm really not sure how I can hook this function without modifying the original module?

#10

I think you just have to do a hook_form_alter and copy the $form from the module and change the options. I think I'll work. Read more on http://api.drupal.org/api/function/hook_form_alter/6 and http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....

#11

thanks works a treat!

nobody click here