Create a form


/**
 * Implements hook_form().
 */
function MY_CUSTOM_FORM_form($node, &$form_state) {
  $form = array();
   
  $form['CUSTOM_FIELD'] = array(
    '#type' => 'textfield',
    '#label' => 'MY_LABEL',
  );
   
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit')
  )
   
  return $form;
}
 
/**
 * MY_CUSTOM_FORM validation handler.
 */
function MY_CUSTOM_FORM_form_validate($node, &$form_state) {
   
}
 
/**
 * MY_CUSTOM_FORM submit handler.
 */
function MY_CUSTOM_FORM_form_submit($node, &$form_state) {
   
}

Call the form by using drupal_get_form. Form can be called inside blocks or pages as a single element or be a part of a build array.

If you're not sure how to use hook form, you can read the Write your first Drupal 7 module article.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.