Pages

Thursday, February 17, 2011

Drupal Module - Form Submit

form_explore.info
name = Form Module Learning
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_form'),
        'access callback' => TRUE,
    );
   
    return $items;
}

/**
 * form implementation
 */
function get_states_form($form, &$form_state){
    $form['name'] = array(
        '#type' => 'fieldset',
        '#title' => t('Provide your full name'),
    );
   
    $form['name']['fname'] = array(
        '#type' => 'textfield',
        '#title' => t('First Name'),
    );
   
    $form['name']['lname'] = array(
        '#type' => 'textfield',
        '#title' => t('Last Name'),
    );
   
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save'),
    );
   
    return $form;
}

/**
 * Implements submit function
 */
function get_states_form_submit($form, &$form_state){   
    drupal_set_message("Your name is: ".$form_state['values']['name']['fname']." ".$form_state['values']['name']['lname']);
}

No comments:

Post a Comment