; Form Module
name = Form Learning
description = Provide Learning For Form Module
package = Learning
version = 1.0
core = 7.x
name = Form Learning
description = Provide Learning For Form Module
package = Learning
version = 1.0
core = 7.x
The module file: form_learning.module
<?php
/**
* Implements drupal hook_menu()
*/
function form_learning_menu(){
$items = array();
/**
* Main menu in the navigation block
*/
$items['learning/form'] = array(
'title' => 'Form Learning',
'page callback' => 'drupal_get_form',
'page arguments' => array('form_1'),
'access callback' => TRUE,
);
/**
* Primary menu tab ( Default)
* Just show the simplest form example
* inherited from the main menu
*/
$items['learning/form/default'] = array(
'title' => 'Simple Box',
'access callback' => TRUE,
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 1,
);
/**
* Primary menu tab
* Show two fieldset
*/
$items['learning/form/data'] = array(
'title' => 'Personal Data',
'page callback' => 'drupal_get_form',
'page arguments' => array('get_data'),
'type' => MENU_LOCAL_TASK,
'access callback' => TRUE,
'weight' => 2,
);
return $items;
}
/**
* The simplest form
* Shown when user click main menu in navigation block
*/
function form_1($form, &$form_state){
$form['description'] = array(
'#type' => 'item',
'#title' => t('This is the first entry of form'),
);
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
);
return $form;
}
/**
* The primary tab menu (not default)
*/
function get_data($form, &$form_state){
/**
* Just showing the description text
*/
$form['description'] = array(
'#type' => 'item',
'#title' => t('A form with fieldset'),
);
/**
* Fielset First: Pesonal Data
*/
$form['data'] = array(
'#type' => 'fieldset',
'#title' => t('Personal Information'),
);
$form['data']['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
);
$form['data']['city'] = array(
'#type' => 'textfield',
'#title' => t('City'),
);
$form['data']['submit'] = array(
'#type' => 'submit',
'#value' => 'Send',
);
/**
* Fieldset second: School
*/
$form['school'] = array(
'#type' => 'fieldset',
'#title' => t('Your School'),
);
$form['school']['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
);
$form['school']['address'] = array(
'#type' => 'textfield',
'#title' => t('Address'),
);
$form['school']['country'] = array(
'#type' => 'textfield',
'#title' => t('Country'),
);
$form['school']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
No comments:
Post a Comment