Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i add my custom form to custom block in my custom module

I've made a custom Drupal module. Inside which I've created a block and a form. How can I make the form appear in the block content? Cheers.

Block Code:

function module_block($op = 'list', $delta = 0, $edit = array()) { 
  $block = array();

  if ($op == "list") {
    // Test
    $block[0]["info"] = t('Block');
  }
  else if ($op == 'view') {
    $block['content'] = module_function();
  }

  return $block;

}


// End module_block

Form Code:

function module_my_form($form_state) {

  $form['email'] = array(
    '#type' => 'textfield',
    '#title' => t('Email'),
    '#required' => TRUE,
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
  );
  return $form;
}

Cheers again for any help.

like image 689
Doyle Avatar asked Jan 12 '11 23:01

Doyle


1 Answers

For anyone looking, change:

$block['content'] = module_function();

to

$block['content'] = drupal_get_form('module_my_form');

Cheers

like image 95
Doyle Avatar answered Oct 18 '22 11:10

Doyle