1 form_example_tutorial.inc | form_example_tutorial_5($form, &$form_state) |
This is Example 5: a basic form with additional element attributes.
This demonstrates additional attributes of text form fields.
Related topics
File
- modules/
examples/ form_example/ form_example_tutorial.inc, line 162 - This is the form API tutorial.
Code
function form_example_tutorial_5($form, &$form_state) {
$form['description'] = array(
'#type' => 'item',
'#title' => t('A form with additional attributes'),
'#description' => t('This one adds #default_value and #description'),
);
$form['name'] = array(
'#type' => 'fieldset',
'#title' => t('Name'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['name']['first'] = array(
'#type' => 'textfield',
'#title' => t('First name'),
'#required' => TRUE,
'#default_value' => "First name",
'#description' => "Please enter your first name.",
'#size' => 20,
'#maxlength' => 20,
);
$form['name']['last'] = array(
'#type' => 'textfield',
'#title' => t('Last name'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}