Not working in Block

midkemia - August 6, 2008 - 14:00
Project:Keyword Autocomplete
Version:5.x-1.0
Component:Code
Category:bug report
Priority:normal
Assigned:rszrama
Status:closed
Description

As best i can tell its not working for my Search form Block.

If i put a term in the block it will return the results in the node with further search option. In this search box it does work You see the small circle to the right of the box.

Any ideas

#1

midkemia - August 6, 2008 - 14:07

Further info that may be contributing

Search block has some theming via

search-block-form.tpl.php

<div align="center"><label for="search_block_form_keys"></label>
<input type="text" maxlength="128" name="search_block_form_keys" id="edit-search_block_form_keys" size="15" value="" title="Enter the terms you wish to search for." class="form-text" />
<input type="submit" src="/files/clips/button-go.gif"  name="op" value="Go"  />
<input type="hidden" name="form_id" id="edit-search-block-form" value="search_block_form" />
<input type="hidden" name="form_token" id="a-unique-id" value="<?php print drupal_get_token('search_block_form'); ?>" /></div>>

#2

midkemia - August 6, 2008 - 15:23

More info

In my template.php i have the following code which accesses the .tpl.php in my last post

/**
* This snippet catches the default searchbox and looks for
* search-block-form.tpl.php file in the same folder
* which has the new layout.
*/
function phptemplate_search_block_form($form) {

  return _phptemplate_callback('search-block-form', array('form' => $form));
}

If i comment this out all works correctly, but it would be nice to be able to theme the box, so the question now becomes how

#3

rszrama - August 7, 2008 - 14:04

I'll look into this when I get home tonight... one thought would be to add a textfield to the settings form where you can specify an alternate search form ID to add the autocomplete to. I may also get away w/ using strpos() to search for a known string within the form ID.

btw, I LOOOOOVE Raymond Feist. Well, his books anyways... haven't met the man. ; ) I've been waiting to find Jimmy the Hand in paperback in my local book store so I can go snap it up. My brother got me hooked starting w/ Magician about 10 years ago or so, and I've read his books now more than any other author. (The closest would probably be Brian Jacques... I was always a Redwall fan and still enjoy the world.)

#4

midkemia - August 7, 2008 - 14:54

It would be great if it can be made to plug straight in and take account if any theming, then everyone could use it with ease :)

In my case the purpose of theming is primarily to change Search to Go (Search is just a little too big)

As to comment on Feist, if you google his website, you will find that Jimmy the Hand is Due for relase in the US any time now. And if that search box had Keyword Autocomplete capability...... :))

#5

rszrama - August 8, 2008 - 02:08
Status:active» postponed (maintainer needs more info)

Curious... when I look at the source on your site, it appears that the form ID is still the same - search_block_form. Since theming happens after the form is built and altered, I wonder if there's actually something in the display of your form that's keeping it from displaying the autocomplete. Can you maybe post up the contents of that form .tpl.php for me to check out?

#6

midkemia - August 8, 2008 - 03:45

Could this be because i am only have Keyword Autocomplete running on the test site ?

#7

midkemia - August 8, 2008 - 04:45

Ok when the code from #2 above is added to template.php
we get the following in the source code and no Autocomplete - this is basically the same as the code in #1
So i am guessing code #2 is calling code #1 preventing Autocomplete from intercepting ?

<div class="content">
<form action="/search/node"  accept-charset="UTF-8" method="post" id="search-block-form">
<div>
<div align="center">
<label for="search_block_form_keys"></label>
<input type="text" maxlength="128" name="search_block_form_keys" id="edit-search_block_form_keys" size="15" value="" title="Enter the terms you wish to search for." class="form-text" />
<input type="submit" src="/files/clips/button-go.gif"  name="op" value="Go"  />
<input type="hidden" name="form_id" id="edit-search-block-form" value="search_block_form" />

Now if we remove the code from #2 we get the following in the source code and all works correctly

<form action="/search/node"  accept-charset="UTF-8" method="post" id="search-block-form">
<div>
<div class="container-inline">
<div class="form-item">
<input type="text" maxlength="128" name="search_block_form_keys" id="edit-search-block-form-keys"  size="15" value="" title="Enter the terms you wish to search for." class="form-text form-autocomplete" />
</div>
<input class="autocomplete" type="hidden" id="edit-search-block-form-keys-autocomplete" value="http://cms2.crydee.com/search/keyword-autocomplete" disabled="disabled" />
<input type="submit" name="op" id="edit-submit" value="Search"  class="form-submit" />

#8

rszrama - August 8, 2008 - 13:57

The only noticeable difference is the id string having underscores instead of dashes. That might represent a problem, though I'm not entirely sure. It could be that it's getting themed before being altered by Keyword Autocomplete, but I just don't see how that would work. Can you post the contents of search-block-form.tpl.php?

#9

midkemia - August 8, 2008 - 14:51

The content of search-block-form.tpl.php can be found in #1 above :)

#10

rszrama - August 8, 2008 - 19:02
Assigned to:Anonymous» rszrama
Status:postponed (maintainer needs more info)» fixed

heh My bad... don't know why I failed to put 2 and 2 together before. :-/

Anyways, it's failing b/c the theme function is overriding the entire HTML output, including what Drupal is automatically adding for the autocomplete. Your best bet would be to alter the form some other way. If all you really need to do is change the text of the button, another way to do it would be to use hook_form_alter() in a custom module.

Alternately, you could just manually put the autocomplete HTML into your theme function that's missing and manually add autocomplete.js in your phptemplate_search_block_form() function.

#11

midkemia - August 8, 2008 - 22:46

Ok 99% of what you just said went right over my head as soon as you said hook :) Hook line and sinker more like :)

But not to be daunted, i looked at your suggested options and had a play, and a play and a play, lots of Drupal searches too and finally stumbled on the solution after finding many close, but not close enough

So we went the module route

In case anyone else has the same or similar problem here is the code used in the module it was found here http://drupal.org/node/62647#comment-263773

it works in drupal 5.7

search_go.info

; $Id $
name = Search_Go
description = Replaces the Search Button with a Go Button.
version = "$Name: DRUPAL-5--1-0 $"
version = "5.x-1.0"
project = "search_go"

search_go.module

<?php

/**
*Impliment hook_form_alter()
*/
function search_go_form_alter($form_id, &$form){
  if ($form_id == 'search_block_form'){
    $form['submit'] = array(
      '#type' => 'submit',
      '#theme' => 'button',
      '#button_type' => 'image',
      '#value' => t('Go'),
      '#attributes' => array('src' => 'search_go.gif')
    );
  }
}

Whether its correctly coded or not, I will leave for others to decide, i just know it works. And is now live on my primary site

Though i guess it woudl be preferable if Keyword Autocomplete were able to handle this type of situation :)

#12

rszrama - August 8, 2008 - 23:31

Looks great! You can actually make it even slimmer:

<?php
function search_go_form_alter($form_id, &$form){
  if (
$form_id == 'search_block_form'){
   
$form['submit']['#value'] = t('Go');
  }
}
?>

Basically, you can just change the value you need to change and not worry about redefining the whole thing.

Kudos to you for figuring all this out. Coding in Drupal is a lot of fun. : )

Also, there really isn't a way for Keyword Autocomplete to work w/ a custom theme function for the form. The reason is your function was basically hard coding the HTML output of the form, whereas by default Drupal would build that dynamically to include the autocomplete.

Also, glad to see the module in use. : D

#13

midkemia - August 9, 2008 - 07:18

That works even better, less code :)

The reason i went the way I did was there seem to be many posts about not being able to change the label of the button, without loosing the submit function.

#14

rszrama - August 9, 2008 - 21:26

Hmm... you know, it just came to me... I wonder if the Formfilter module would work.

http://drupal.org/project/formfilter

Haven't used it, but I found it after a search... saw it when it first came out.

#15

Anonymous (not verified) - August 23, 2008 - 21:33
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.