I'm trying to make a custom search block, so I implemented the exact same code as I used in another search block (block-search.tpl.php).

  <form action="<?php print base_path() ?>search/node/"  accept-charset="UTF-8" method="post" id="search-block-form">
    <input type="text" name="search_block_form_keys" id="searchfield"  class="swap_value"  value="enter search terms" />
    <input type="button" name="op" id="searchgo" value="&amp; go." />
	<input type="hidden" name="edit[form_token]" id="edit-search-block-form-form-token" value="<?php print drupal_get_token('search_form'); ?>" />
    <input type="hidden" name="form_id" id="edit-search-block-form" value="search_block_form"  />
  </form>

and I get the "Validation error, please try again. If this error persists, please contact the site administrator."

I've gone back to no custom file and I still get this validation error with a default search block.

I'm stumped and this is a showstopper on this project :(

Thanks for any help.

Cheers,

Adam

Comments

davedelong’s picture

That validation error (which I've come across myself) usually comes up when you have two different forms that are attempting to use the same form id.

HTH,

Dave

nimzie’s picture

How do I work around this?

nimzie’s picture

Or rather yet - what is the base code for a generic search block?

I can start from there although I'm taking code from 2 other working implementations and they won't work in my block : same errors.

Thanks for any help.

Cheers,

Adam

davedelong’s picture

In a site I admin, we need custom rendering of the default search form (the one in the top right), so we implemented theme_search_theme_form in our theme's template.php. However, this theming function doesn't exist beyond Drupal 5. I'm not sure what the Drupal 6 equivalent would be. Here's what ours looked like:

 function ourtheme_search_theme_form($form) {
	$form['submit']['#theme'] = 'button';
	$form['submit']['#button_type'] = 'image';
	$form['submit']['#attributes'] = array(
		'src' => '/'. drupal_get_path('theme','ourtheme').'/images/go.gif',
		'alt' => t(Search)
	);
	$output = drupal_render($form);
	$output = str_replace('div', 'span', $output);
	$output = '<label accesskey="s" for="edit-search-theme-form-keys">Search BYU CS</label> ' . $output;
	$output .= ourtheme_header_login();
	return $output;
}

function ourtheme_button($element) {
	$return_value = theme_button($element);
	if ($element['#button_type'] == 'image') {
		$return_value = str_replace('type="submit"','type="image"',$return_value);
	}
	return $return_value;
}

function ourtheme_header_login() {
	global $user;
	if (is_object($user) && $user->uid) {
		$output = '<span id="userLogin">' . theme('username', $user) . ' | <a href="/logout">Logout</a></span>';
	} else { 
		$output = '<span id="userLogin"><a href="/user?' . drupal_get_destination() . '">Login</a>';
	}
	return $output;
} 

We included the login link inside the rendered form tag in order to make sure that the CSS would render things properly (we're building off legacy code :P)

HTH,

Dave

nimzie’s picture

Odd - I don't know what I'm missing to get these functions to hook. My theme is called brightwhite and I preface everything with brightwhite_ and rename the functions / calls to them. It doesn't seem to take @ all.
Any suggestions? I'm kind of lost on this one.
THing is, I've tried this on several different sites and it's worked... with the block-search.tpl.php file approach. Anyone should be able to drop that in their site folder and see if it works.??

nimzie’s picture

I went with this approach. Now, I've got a little module and off we go. Drop me a line if you'd like it.

http://agaricdesign.com/note/validation-error-search-form-contact-site-a...

Cheers!

khan2ims’s picture

Yes, thats what I do whenever I come acroos thevalidation error. Simply run the cron job and you will see the error/ warning going away in fumes :-)

But it needs a more reliable reason as to wht it happens !

Imran Khan
Project Manager
New Earth Marketing