name = Form Module Learning
description = This form provide a way for learning
package = Exploration
version = 1.0
core = 7.x
description = This form provide a way for learning
package = Exploration
version = 1.0
core = 7.x
form_explore.module
<?php
/**
* Implements hook_menu()
*/
function form_explore_menu(){
$items = array();
$items['explore/main'] = array(
'title' => 'Form State',
'page callback' => 'drupal_get_form',
'page arguments' => array('get_states'),
'access callback' => TRUE,
);
return $items;
}
/**
* form implementation
*/
function get_states($form, &$form_state){
// Provide radios options
$form['position'] = array(
'#type' => 'radios',
'#title' => t('Your Excellence'),
'#options' => drupal_map_assoc( array( t('Hacker'), t('Teacher'), t('Writer') )),
);
// fieldset for hacker options
$form['hacker'] = array(
'#type' => 'fieldset',
'#title' => t('Personal data'),
//states
'#states' => array(
'visible' => array(
':input[name="position"]' => array( 'value' => t('Hacker')),
),
),
);
$form['hacker']['lang'] = array(
'#type' => 'select',
'#title' => t('Your programming language'),
'#options' => array(
1 => 'Java',
2 => 'C/C++',
3 => 'Python',
4 => 'C#',
),
);
// fieldset for teacher options
$form['teacher'] = array(
'#type' => 'fieldset',
'#title' => t('Personal subject'),
// states
'#states' => array(
'visible' => array(
'input[name="position"]' =>
array( 'value' => t('Teacher')),
),
),
);
$form['teacher']['subject'] = array(
'#type' => 'checkboxes',
'#title' => t('Your subject'),
'#options' => drupal_map_assoc( array( t('Physics'),
t('Biology'), t('History'), t('Medicine') )),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Send'),
);
return $form;
}
No comments:
Post a Comment