0
votes

DRUPAL 6.X
I have this custom form constructor inside my custom module which is invoke through ajax request. I’m attempting to theme this form with the template file reside in my theme directory. For that matter, I’ve registered my theme inside template.php file which reside in my theme folder. Here’s how this file looks –

function my_theme() {
return array(
    'searchdb' => array(
    'arguments' => array('form' => NULL),
    'template' => 'searchform',
    )
);      

}

And the following is the excerpt of module code –

function test_menu() {
$my_form['searchdb'] = array(
    'title' => 'Search db',
    'page callback' => 'get_form',
    'page arguments' => array(0),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
    );

return $my_form;

}

function get_form($formtype){
switch($formtype){
    case 'searchdb' :
        echo drupal_get_form('searchdb');
        break;
}

}

function searchdb(){
$form['customer_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Customer Name'),
    '#size' => 50,
    '#attributes' => array('class' => 'name-textbox'),
);
return $form; 

}

As you can imagine, this is not working at all. Just to test if my theme is even registered, I’ve also tested with theme function but, it’s not called. I've checked template file name and form-id(through the outputted html source) and everything seems ok. I would be glad if anyone could point me to the right direction.

1
you can get rid of the get_form function by using drupal_get_form as your page callback value and array('searchdb') as the page arguments value. - gapple
I've tried that as well but drupal just won't recognize my theme register inside template.php. I kind of lost as to what to do to make drupal recognize my theme for the form. - Andrew

1 Answers

0
votes

I ran into the same issue with my forms. It has to do with the PHP version and the php function that is called in the theming process to get output from your theme function: call_user_func_array.

In php 5.2 and below it accepts the structured $form arrays that Drupal passes in. However, in php 5.3 it dies.

I solved my issue by rolling back my php version to 5.2.14.

This solution applies to Drupal 6. I haven't tested it in Drupal 7 as D7 claims to be php 5.3 compatible.