The following is the contents of my "mymodule.module" file, which creates a form with an "email" field.
// Implements a hook.
function mymodule_menu() {
$items = array();
$items['form'] = array(
'title' => 'My Form',
'description' => t('My Form'),
'page callback' => 'drupal_get_form',
'page arguments' => array('mymodule_myform'),
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
'menu_name' => t('My Menu'),
);
return $items;
}
function mymodule_myform($form, &$form_state) {
$form['contact_information'] = array(
'#title' => t('Contact Information'),
'#type' => 'fieldset',
'#description' => t('Please provide an e-mail address for us to contact you with further instructions.'),
);
$form['contact_information']['email'] = array(
'#type' => 'textfield',
'#title' => t('E-mail address'),
'#id' => 'email',
'#attributes' => array('class' => array('validate[required,custom[email]]')),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function mymodule_myform_validate($form, &$form_state) {
}
function mymodule_myform_submit($form, &$form_state) {
drupal_set_message(t('Thanks for submitting the form.'));
}