Hi everybody i wish that this will find you well.
i have a problem with uc_hotel module, i want to add a select
list("destination") to the room search block and involve it to the search engine.
I tried to create my hook module (customsearch) with 2 files .module and
.info. I made into .module file my hook fucntion and i tried some tricks i
could create a select list but i couldn't involve it in my room search engine
and I want also reorder the form to place my select list before the submite button.
Please if you can help me step by step cause I m beginner I will be gratefull.

Comments

larowlan’s picture

Component: Code » Miscellaneous
Assigned: amineBK » Unassigned
Issue tags: -hotel booking ubercart

Hi
To get you started have a look here: #1071866: Add additional fields to search form.
If you like, post what you've done so far and I'll review it.
Regarding weighting of elements, the actual layout of the search form is governed by the template (hotel_booking_search_form.tpl.php from memory) - if you copy that to your theme folder, flush your caches and then edit the version in your theme folder - you should be able to add in new fields where you require theme. Have a look at the function template_preprocess_hotel_booking_search_form in the file hotel_booking.module to see how the variables are created, you can replicate elements of that logic if you define your own preprocessor in your theme's template.php

Lee

amineBK’s picture

Hi.
I have already read the http://drupal.org/node/1071866 sorry i can't understand
here is what i have done. I copied the hotel_booking_search_form.tpl.php in the template folder like you told me

1. I created a new field :

print $destination;

I can see the div script but its empty

2. and I create also a new preprocess function in my them's template.php i called it template_prepro_hotel_booking_search_form

function template_prepro_hotel_booking_search_form(&$vars) {
  $form = $vars['form'];
  drupal_add_css(drupal_get_path('module', 'hotel_booking') .'/css/hotel_booking_search.css');

  $vars['destination'] = drupal_render($vars['form']['search']['destination']);
  $vars['check_in'] = drupal_render($vars['form']['search']['check_in']);
  $vars['nights'] = drupal_render($vars['form']['search']['nights']);
  $vars['adults'] = drupal_render($vars['form']['search']['adults']);
  $vars['submit'] = drupal_render($vars['form']['search']['submit']);
  if ($vars['form']['link']) {
    $vars['link'] = drupal_render($vars['form']['search']['link']);
  }
  if ($vars['form']['results']) {
    $vars['results'] = drupal_render($vars['form']['results']);
  }
  if ($vars['form']['search']['smoking']) {
    $vars['smoking'] = drupal_render($vars['form']['search']['smoking']);
  }
  if ($vars['form']['search']['children']) {
    $vars['children'] = drupal_render($vars['form']['search']['children']);
  }
  if ($vars['form']['page'] && $vars['form']['page']['#value']) {
    $vars['template files'][] = 'hotel_booking_search_form_page.tpl.php';
  }
  else {
    $vars['template files'][] = 'hotel_booking_search_form_block.tpl.php';
  }
  $vars['page'] = FALSE;
  if (isset($vars['form']['page']) && $vars['form']['page']['#value']) {
    $vars['page'] = TRUE;
  }
}

Can you please verify the function if its true and tell me what i must do after these steps

larowlan’s picture

You also need a form_alter hook in your module (as mentioned in the linked issue).
Please post what you have there - ie where you setup the destination field.
Also your function needs to be preprocess not prepro

amineBK’s picture

this is my hook function but i cant involve it into the search engine
sorry if i dont understand quiqly im a beginner
custom search is my module

/**
* Implementation of hook_FORM_ID_alter().
*/

function customsearch_form_hotel_booking_search_form_alter(&$form, &$form_state) {
    $form['destination'] = array(
      '#type' => 'select', 
      '#title' => t('Destination'), 
      '#required' => TRUE, 
      '#options' =>array ( 'Tunisie' => array(
                           Gammarth => t('Gammarth'),
                           Hammamet => t('Hammamet'),
                           Monastir => t('Monastir'),  
                           Sousse => t('Sousse'),
                           Tabarka => t('Tabarka'),
                           Tunis => t('Tunis')
                           ), 'Turquie' => array(Istanbul => t('Istanbul')) ),
      );
 
}

larowlan’s picture

try changing $form['destination'] to $form['search']['destination']

amineBK’s picture

Hi.
tell me please if i must modify the hotel_booking_theme, hotel_booking_search_results, hotel_booking_get_available_rooms, hotel_booking_search_form_submit and hotel_booking_calculate_prices functions ?
thanks

larowlan’s picture

Hi
No you don't touch any of the module functions, your module makes changes to what the module provides.
Did you get your field to work?
You can check that your module is working as expected by installing devel module and using the following code at the end of your form alter function

dsm($form);
amineBK’s picture

Sorry i tried but i cant have what i want. i will close the issue until someone will post the answer.