phpdrupaldrupal-7drupal-fapidrupal-forms

create a custom form inside a block in drupal 7


I know how to use a module to create a block and I know how to create a custom form using form api.

now, i want to add this custom form inside the block I create.


Solution

  • Use the following code (hook_block_view):

     function yourmodule_block_view($delta='') {
         $block = array();
         switch($delta) {
            case 'block_name':
              $block['subject'] = t("Block Title"); 
              $block['content'] = drupal_get_form('your_form_id');
              break;
         }
         return $block;
     }