0

I know there is a lot of documentation on this function on google, but I am still not able to get this hook to run for my holidayautosxml_carsearch_form. Could anyone advise on what I am doing wrong.

The Theme function is running fine. If I put exit(); in that function I get white screen of death. However if I put exit(); in the template_preprocess function nothing happens.

I have cleared all the caches.

my template is called holidayautosxml-carsearch.tpl.php and it is located in the module folder.

Here is my theme function

function holidayautosxml_theme(){
return array(
            'holidayautosxml_carsearch' => array(
                    'template'=>'holidayautosxml-carsearch',
                    'render element'=>'form',
            ),

    'halocationresults' => array(
        'template' => 'halocationresults',
        'variables' => array('haresults' => NULL,),
    ),
    'hapriceslist' => array(
        'template' => 'hapriceslist',
        'variables' => array('haprices' => NULL,),
    ),
);
}

Here is my template_preprocess function

function template_preprocess_holidayautosxml_carsearch(&$variables){

$variables['holidayautosxml_carsearch'] = array();
$hidden = array();
//Provide variabels named after the form keys so themers can print each element independently.
foreach (element_children($variables['form']) as $key){
    $type = $variables['form'][$key]['#type'];
    if ($type == 'hidden' || $type == 'token'){
        $hidden[] = drupal_render($variables['form'][$key]);
    }
    else{
        $variables['holidayautosxml_carsearch'][$key] = drupal_render($variables['form'][$key]);
    }
}
//Hidden form elements have no value to Themers. no need for seperation.
$variables['holidayautosxml_carsearch']['hidden'] = implode($hidden);
//collect all form elementsto make it easier to print the whole form
$variables['holidayautosxml_carsearch'] = implode($variables['holidayautosxml_carsearch']);
}

and here is my form function

function holidayautosxml_carsearch_form($node, &$form_state){

    $country_list = _get_country_list();
    $form['country'] = array(
            '#type'=>'select',
            '#title'=>'Select Country',
            //'#description'=>'Select the country where you want to collect the car',
            '#options'=>$country_list,
            '#ajax' => array(
                'callback' => 'update_officename_autocomplete',
                'wrapper' => 'haofficename',
            ),
    );

    $citylist = _get_city_list($form_state['values']['country']);

$form['officename'] = array(
    '#type'=>'select',
    '#title'=> t('Location'),
    //'#description' => t('Select the location where you want to pick up the car'),
    '#required' => TRUE,
            '#options' => $citylist,
            '#width' => 50,
            //'#autocomplete_path'=>'location-autocomplete',
            '#prefix' => '<div id="haofficename">',
            '#suffix' => '</div>',
);


    if (!empty($form_state['values']['country'])){
        $form['officename']['#autocomplete_path'] = 'location-autocomplete/' . "{$form_state['values']['country']}";
    }
    $dateformat = 'd-m-Y H:i';
    $form['datefrom'] = array(
        '#required'=>TRUE,
        '#type'=>'date_popup',
        '#date_format'=>$dateformat,
        '#title'=>t("Pickup date"),
        //'#description'=>t("The date you are picking up the car"),

        );

    $form['dateto'] = array(
        '#required'=>TRUE,
        '#type'=>'date_popup',
        '#date_format'=>$dateformat,
        '#title'=>t("Dropoff date"),
        //'#description'=>t("The date you are bringing the car back"),
    );

$form['submit'] = array(
'#type'=>'submit',
'#value'=>'Search Now',
'#submit'=>array('holidayautosxml_carsearch_form_submit'),
);

return $form;
}
2

I think it should be holidayautosxml_preprocess_holidayautosxml_carsearch(&$variables). Basically the syntax is [yourModuleName|yourThemeName]_preprocess_[themeFunctionName](&$variables).

Also you need to flush your cache after you make the change.

| improve this answer | |
  • Hi Junedkazi, I tried what you said but that does not work. I think you only have to specify the module name first if you are refering to theme declared in another module. But this Theme is declared by the same module. Also this is a template_preprocess function, your suggestion does not mention template in the function name so I am not sure how Drupal would call that function when preprocessing templates. Thanks any way Simon – PrestonDocks Sep 25 '12 at 18:47
  • If you are doing it at the module level then it is modulename_preprocess_[themeFunctionName](&$variables) and if you doing it at the theme level then themename_preprocess_[themeFunctionName](&$variables). – junedkazi Sep 25 '12 at 19:10
0

OK, I found the solution. The code I posted above only seems to work when I add, $form['#theme'] = 'holidayautosxml_carsearch'; to the form specification.

Hope this helps someone.

Simon

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.