开发者

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

开发者 https://www.devze.com 2023-02-04 03:14 出处:网络
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.

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 开发者_JAVA百科($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.


For anyone looking, change:

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

to

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

Cheers

0

精彩评论

暂无评论...
验证码 换一张
取 消