I want to retain dropdown list value, so that when ever someone select the option from the dropdown list should retain that value after performing the action.
/*
*implements hook_menu().
*/
function dropdown_page_menu(){
$items = array();
$items['page/layout/%'] = array(
'title' => 'Select Layout',
'page callback' => 'drupal_get_form',
'page arguments' => array('dropdown_page_select_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* Implements hook_block_info().
*/
function dropdown_page_block_info() {
$blocks = array();
$blocks['dropdown_page_select_form'] = array(
'info' => t('Select Layout'),
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function dropdown_page_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'dropdown_page_select_form':
$block['subject'] = t('Select Layout');
$block['content'] = drupal_get_form('dropdown_page_select_form');
break;
}
return $block;
}
function dropdown_page_select_form($form, &$form_state){
$options = array(
'select' => t('Select'),
'layout_1' => t('Layout 1'),
'layout_2' => t('Layout 2'),
'layout_3' => t('Layout 3'),
);
$form['choice'] = array(
'#type' => 'select',
'#options' => $options,
'#title' => t('Select your layout'),
'#default_value' => $form_state['choice']['type']
);
$form['submit'] = array(
'#type' => 'submit',
'#value'=> t('Go'),
);
return $form;
}
function dropdown_page_select_form_submit($form, &$form_state){
switch ($form_state['values']['choice']){
case layout_1 : {
//echo 'hi';die;
drupal_goto("layout_1".$options);
break;
}
case layout_2 : {
//echo 'no';die;
drupal_goto("layout_2".$options);
break;
}
case layout_3 : {
drupal_goto("layout_3".$options);
break;
}
default: {
print 'Select it!';
}
}
drupal_set_message(t('Your layout %input', array('%input' => $form_state['value']['choice'])));
}