Hello Gurus,
I'm creating a custom theme and need to heavily alter the search block form. I've done a lot of digging before posting here, and so far I can call a function that will wrap my form a bit differently (... to ...).

The challenge is that my custom function is returning an empty string or isn't being accepted or is behaving badly in general. I could simply return "HELLO" and nothing will show on the site. I know that my function is being called and I can print_r() the $variables. I just don't see what is being returned there.

/**
* hook_theme()
*/
function ss30_theme($existing, $type, $theme, $path) {
  return array(
'ss30_search_block_form' => array(
      'variables' => array('links' => array(), 'attributes' => array(), 'type' => NULL),
    ),
  );
}
/**
* hook_form_alter()
*/
//alter forms
function ss30_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'search_block_form') {
$form['#theme_wrappers'] = array(0 => 'ss30_search_block_form');
}
}
//get rid of the extra <div></div> right after the start and end of <form></form>
//taken from: https://api.drupal.org/api/drupal/includes!form.inc/function/theme_form/7
function ss30_search_block_form($variables) {
  //die('made it this far...');
  $element = $variables['element'];
  if (isset($element['#action'])) {
    $element['#attributes']['action'] = drupal_strip_dangerous_protocols($element['#action']);
  }
  //element_set_attributes($element, array('method', 'id')); //this is generating an error, will revisit later...
  if (empty($element['#attributes']['accept-charset'])) {
    $element['#attributes']['accept-charset'] = "UTF-8";
  }
  return '<form' . drupal_attributes($element['#attributes']) . '>' . $element['#children'] . '</form>';
}

Any thoughts on what I'm doing wrong? My guess is that ss30_theme() is set incorrectly somehow?

Thanks for the nudge in the right direction in advance. :D

Best regards,

Comments

You've got a few problems. The first is that this:

<?php
function ss30_search_block_form($variables) {
?>

Should be this:

<?php
function theme_ss30_search_block_form($variables) {
?>

You need to prepend theme functions with theme_

However, once you have fixed this, you are going to run into all sorts of problems by screwing with the form tag like you are. In Drupal, you should never be outputting form tags, they should be outputted using the Drupal Form API. So while my above fix will get you further, you are going to run into a whole whack of problems with the code you are trying to use.

Jaypan
Our newest Drupal site: PacificAikido.com (Drupal showcase)

Hello Jaypan,
Thanks for your super fast response!

After many struggles, I'm starting to agree that messing with tags and not sticking with the API strictly is a bad idea. On the flip side, I really need to rearrange the elements and containers of a search form.

What are your thoughts on making a new module/search form? Is it possible to create a custom form that submits to the search page? If so, I'll start moving in that direction instead of my current messy road of destruction. ;)

Thanks again,

UPDATE - Pondering:
http://stackoverflow.com/questions/3368377/create-a-custom-search-form-d...
https://drupal.org/project/custom_search
https://drupal.org/node/154137 (maybe just change the tree here, just not liking the default form wrapper right now...)

ANOTHER UPDATE:
I'm getting close to having a "working" version finished. Maybe I could post it for better practice suggestions shortly...

Worlds to explore. Worlds to create.
Blog: http://www.christopherstevens.cc/blog
Twitter: http://www.twitter.com/owntheweb

I'm sorry, your post was sort of all over the place. Can you please ask a specific question or two to be answered? Thank you.

Jaypan
Our newest Drupal site: PacificAikido.com (Drupal showcase)