Form in a Block

Public

Creating a Block with form

Get raw version
php
  1. function YOURMODULE_block_info()
  2. {
  3.     $blocks = array();
  4.  
  5.     $blocks['custom_block'] = array(
  6. 'info' => t('Custom block example'),
  7. 'title' => t('Custom block example'),
  8. 'region' => 'content',
  9. 'status' => 1,
  10. );
  11.  
  12. return $blocks;
  13. }
  14.  
  15. function YOURMODULE_block_view($delta = '')
  16. {
  17.     $block = array();
  18.  
  19. switch ($delta) {
  20. case 'custom_block' :
  21.             $block['content'] = YOURMODULE_block_content();
  22. break;
  23. }
  24.  
  25. return $block;
  26. }
  27.  
  28. function YOURMODULE_block_content()
  29. {
  30. return drupal_get_form('my_custom_form');
  31. }
  32.  
  33. function my_custom_form($form, &$form_state)
  34. {
  35. // Build your form
  36.  
  37. return $form
  38. }