Monday, December 16, 2013

Display form fileds on radio button select using #states

$form['membership_type'] = array(
'#type' => 'select', 
'#title' => t('Select Membership type'), 
'#default_value' => $node->selectbox, 
'#options' => $membership_type, 
'#description' => t('Choose an option'),
'#required' => TRUE,
  );
 $form['conditions1'] = array(
    '#type' => 'radios',
    '#title' => t('Select Attribute'),
 '#options' => array(0 => 'Rooms', 1 => 'Others'),
  );
  
  $form['using_free_nights_discount_forguest'] = array(  '#type' => 'textfield',
'#type' => 'textfield',
'#title' => t('Discount For Guest When Using Free Nights'), 
'#default_value' => $using_free_nights_discount_forguest,
'#states' => array(
'visible' => array(
  ':input[name="conditions1"]' => array('value' => t('0')),
),
'invisible' => array(
  array('value' => t('1')),
),
), 
'#size' => 29,
);
$form['notusing_free_nights_discount_forguest'] = array(  '#type' => 'textfield',
'#type' => 'textfield',
'#title' => t('Discount For Guest When Not Using Free Nights'), 
'#default_value' => $notusing_free_nights_discount_forguest, 
'#states' => array(
'visible' => array(
  ':input[name="conditions1"]' => array('value' => t('0')),
),
'invisible' => array(
  array('value' => t('1')),
),
),
'#size' => 29,
);
$form['notusing_free_nights_discount_formembers'] = array(  '#type' => 'textfield',
'#type' => 'textfield',
'#title' => t('Discount For Members When Not Using Free Nights'), 
'#default_value' => $notusing_free_nights_discount_formembers, 
'#states' => array(
'visible' => array(
  ':input[name="conditions1"]' => array('value' => t('0')),
),
'invisible' => array(
  array('value' => t('1')),
),
),
'#size' => 29,
);
$form['room_attribute_id'] = array(  '#type' => 'textfield',
'#type' => 'hidden',
'#title' => t('Room Attribute Id'), 
'#default_value' => 6, 
'#states' => array(
'visible' => array(
  ':input[name="conditions1"]' => array('value' => t('0')),
),
'invisible' => array(
  array('value' => t('1')),
),
),
'#size' => 29,
);
  
  $form['room_attributes'] = array(
'#type' => 'select', 
'#title' => t('Select Room Atributes'), 
'#default_value' => $node->selectbox, 
'#options' => $room_attributes,
'#description' => t('Choose an option'),
'#states' => array(
'visible' => array(
 ':input[name="conditions1"]' => array('value' => t('1')),
),
'invisible' => array(
  array('value' => t('0')),
),
    ),
  );
 
 $form['discount'] = array(
'#type' => 'textfield',
'#title' => t('Discount Rate'), 
'#size' => 29,
'#states' => array(
'visible' => array(
  ':input[name="conditions1"]' => array('value' => t('1')),
),
'invisible' => array(
  array('value' => t('0')),
),
),
);

$form['submit'] = array(
'#name' => 'submit',
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;

No comments:

Post a Comment