Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
afagioliComment #2
larowlanThanks, 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
Comment #3
afagioliHi 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
Comment #4
larowlanAgreed
Comment #5
afagioli