Creating a custom form from a module in Drupal 6


This will check if the user has permissions to view the form

function myform_perm() {
  return array('access myform content');


What url will lead us to the form, useful to start it with ‘admin’ so non-admin users can’t access it.

function myform_menu() {
  $items = array();
  $items['path/to/my/form'] = array(
    'title' => t('My Form'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('myform_form'),
    'access arguments' => array('access myform content'),
    'type' => MENU_NORMAL_ITEM,
  return $items;


function myform_form() {
  $form['message'] = array(
    '#type' => 'textarea',
    '#title' => t('Message'),
    '#required' => TRUE,
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Send')
  return $form;


function myForm_validate($node, &$form) {
  if (isset($node->end) && isset($node->start)) {
    if ($node->start > $node->end) {
      form_set_error('time', t('An event may not end before it starts.'));

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s