Use case: show Widget search block with custom default nights and adults [today, we can only show that block with '1' default value]

a)
hotel_booking.module:234

Add form element for block configuration

      $form['default_nights'] = Array(
        '#type'          => 'select',
        '#title'         => t('Default Nights'),
        '#default_value' => variable_get('hotel_booking_block_default_nights', '2'),
        '#options'       => Array(1 => 1,2 => 2,3 => 3,4 => 4,5 => 5,6 => 6,7 => 7,8 => 8 ),
        '#description'   => t('Select defaut value for Nights.'),
      );

      $form['default_adults'] = Array(
        '#type'          => 'select',
        '#title'         => t('Default Adults'),
        '#default_value' => variable_get('hotel_booking_block_default_adults', '2'),
        '#options'       => Array(1 => 1,2 => 2,3 => 3,4 => 4,5 => 5,6 => 6,7 => 7,8 => 8 ),
        '#description'   => t('Select defaut value for Adults.'),
      );

b)
hotel_booking.module:273
Save submitted values for default adultns and defaults nights [case 'save':]

      variable_set('hotel_booking_block_default_adults', $edit['default_adults']);
      variable_set('hotel_booking_block_default_nights', $edit['default_nights']);

c)
hotel_booking.module:339
Apply selected default value for nights for Search Room widget

'#default_value' => variable_get('hotel_booking_block_default_nights', '2') ,

d)
hotel_booking.module:357
Apply selected default value for adults for Search Room widget

'#default_value' => variable_get('hotel_booking_block_default_adults', '2') ,

sponsored by http://noteurbane.com

Comments

afagioli’s picture

Assigned: afagioli » Unassigned
larowlan’s picture

Thanks, this is under development with session based saving of what the user searched for so if they went away and came back it would remember their choices

afagioli’s picture

Hi larowlan.
My code above solves a different use case.
"A brand new user comes for the first time on my site. A "Search Rooms" form exposed fields with most popular value as default"
This will shorten navigation from 2 useless action for most of users on the site. [see it in action at http://www.hostelworld.com ]

I agree with you that the second time same user performs a new search, we'd better to get previous values from $_SESSION

larowlan’s picture

Agreed

afagioli’s picture

Status: Needs review » Closed (fixed)