views:

22

answers:

1

I have this code that implements hook_form_alter for durpal search form and adds couple of new elements there. I have also added theme overwrite code in my template.php for the said form. In addition to this, I also pass form elements there. Everything works fine - adds new elements, theme is used;but, here's the problem. When I try to render each element of form with drupal_render, it doesn't show up anything. I've checked the contents of $form array and, it has all the necessary form data. This is the except of my code -

mymod.module

function mymod_form_alter(&$form, $form_state, $form_id) {
    switch ($form_id) {
        case 'search_theme_form':           
            $form['prop_type'] = array(
               '#type' => 'select',
               '#default_value' => 'Selection A',
               '#options' => array("Selection A","Selection B"),
               '#attributes' => array('class'=>'Bold'),     
        );
        break;
   }
}

template.php -

 function mytheme_theme() {
    return array(
        'search_theme_form' => array(
            'arguments' => array('form' => NULL),       
            'template' => 'search_myblock_form',        
        ),

    );

}

And there is also one weird problem, which is, devel's dsm couldn't even show what's inside $form. I had to use print_r to get the string value first and feed it to dsm for display. For what is worth, another thing is, inside my theme template, there is this variable($search_form) with all my form elements rendered. As I want to theme individual element in different way, I can't use it; I like to render individual element by myself.

A: 

hook_theme should be inside your module, not template.php.

But it seems you don't need form_alter and such at all. Template.php is there to override these theme functions then:

function MYTHEMENAME_search_theme_form($form) {
  return "<h1>ceci nes't pas un form</h1>";
}

Then refresh your theme registry and you should see your h1-line appearing on the place of the form.

berkes
I don't have problem with hook_theme being in template cuz it is used and my template receive $form array as well. But, when I try to render each element drupal_render, it doesn't show anything. I've checked and $form contains all the elements I needed. Right now, I have no choice but to use $search which contains rendered elements enclosed in tags created by search module itself.
Andrew
No. You do have a problem with hook_theme in template.php, cuz your solution does not work. As per you question :)
berkes