Drupal Form API Cheat Sheet
Drupal Form API Cheat Sheet
1. Text Field
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#default_value' => 'Default Value',
'#size' => 60,
'#maxlength' => 128,
);
2. Text Area
3. Checkbox
$form['checkbox'] = array(
'#type' => 'checkbox',
'#title' => t('Content'),
);
dishanphilips.com - https://www.drupal.org/u/dphilips
4. Checkboxes
$form['checkboxes'] = array(
'#type' => 'checkboxes',
'#title' => 'Checkboxes',
'#default_value' => array('value1','value2'),
'#options' => array(
'value1' => 'Label 1',
'value2' => 'Label 2',
'value3' => 'Label 3',
),
'#multiple' => true,
);
5. Radio
$form['radios'] = array(
'#type' => 'radios',
'#title' => 'Radios',
'#default_value' => array('value1'),
'#options' => array(
'value1' => 'Label 1',
'value2' => 'Label 2',
'value3' => 'Label 3',
),
);
6. Button
$form['button'] = array(
'#type' => 'button',
'#value' => t('Button'),
);
7. Submit
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
dishanphilips.com - https://www.drupal.org/u/dphilips
8. Password
$form['password'] = array(
'#type' => 'password',
'#title' => t('Password'),
'#size' => 10,
'#maxlength' => 64,
);
9. Password Confirm
$form['password'] = array(
'#type' => 'password_confirm',
'#title' => t('Password Confirm'),
'#size' => 10,
);
$form['image'] = array(
'#type' => 'managed_file',
'#name' => 'custom_image_file',
'#title' => t('Image'),
'#size' => 100,
'#upload_location' => 'public://',
);
11. File
$form['file'] = array(
'#type' => 'file',
'#name' => 'custom_image_file',
'#title' => t('Upload File'),
'#size' => 100,
);
$form['filedset'] = array(
'#type' => 'fieldset',
'#title' => t('Fieldset'),
'#collapsible' => true,
'#collapsed' => false,
);
dishanphilips.com - https://www.drupal.org/u/dphilips
13. Markup
$form['markup'] = array(
'#type' => 'item',
'#title' => t('Markup'),
'#markup' => '<p>Markup</p>',
);
dishanphilips.com - https://www.drupal.org/u/dphilips