How to Create form in PHP based Drupal as a module?



<?php
function appointment_menu($may_cache) {
   
$items = array();
   
$items[] = array(
   
'path' => 'app',
   
'title' => t('App'),
   
'callback' => 'drupal_get_form'// tell drupal to display a form
   
'callback arguments' => array('appointment_form'), // arguments for the callback have to be in an array. The form name is now 'appointment_form'
   
'access' => user_access('access content'),
    
'type' => MENU_CALLBACK);
    return
$items;
}

// Builder function needs the same name as form
function appointment_form() {
   
$form['name'] = array(
   
'#type' => 'textfield',
   
'#title' => t('Name'),
   
'#size' => 30,
   
'#maxlength' => 64);
  ...
 
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
 
$output = drupal_get_form('appointment_form', $form);
  return
$output;
}

// Validate function is form name with 'validate' suffix
function appointment_form_validate($form_id, $form_values) {
  
form_set_error('', t('Error messages show here.'));
}

// Submit function is form name with 'submit' suffix
function appointment_form_submit($form_id, $form_values) {
   
drupal_set_message(t('Your form has been saved.'));
}
?>


COMMENTS