When dealing with Form API in Drupal 7 there have tow partsare two major steps:
create and implement form in module
In this step you are set up the Form ,Validate and submit.
function form_example() {
$form['first_name']=array(
'#type' => 'textfield',
'#title' => t('First name'),
'#description' => t('Enter first name'),
);
$form['last_name']=array(
'#type' => 'textfield',
'#title' => t('Last name'),
'#description' => t('Enter last name'),
);
$form['submit_button'] = array(
'#type' => 'submit',
'#value' => t('Click Here!'),
);
return $form;
}
function form_example_validate($form, &$form_state) {
}
function form_example_submit($form, &$form_state) {
}
Step 1: Create and implement the form in a module
In this step 1, you will setup the form, and then validate and submit the form, as further detailed below.
a) Setup the form
function form_example() {
$form['first_name']=array(
'#type' => 'textfield',
'#title' => t('First name'),
'#description' => t('Enter first name'),
);
$form['last_name']=array(
'#type' => 'textfield',
'#title' => t('Last name'),
'#description' => t('Enter last name'),
);
$form['submit_button'] = array(
'#type' => 'submit',
'#value' => t('Click Here!'),
);
return $form;
}
function form_example_validate($form, &$form_state) {
}
function form_example_submit($form, &$form_state) {
}
b) Validate and submit the form
Now the form is ready to displaybe displayed. one
One way to display the form, is usingto theme ofthe form in the module toand then print the form.
Then create theme-contact-form.tpl.phptheme-contact-form.tpl.php
in the module file and print the form:
With all previous steps for create and implementcomplpeted, the form is created and implemented in the module.
- Style form from theme layer as in this question
Step 2: style the form
To style the form from theme layer, refer to How to a use a template file to theme a form?