I am trying to call a custom form in a block. The form is written in my custom module. I tried different ways to call the form, but not getting the form.

Here is the syntax, I last tried.

$form = drupal_get_form('my_custom_form');
print drupal_render($form); 
//my_custom_form is my form_id



Here is the link I found a similar question, but didn't get the correct solution for my question. Form within a block

  • I tried that way. The below answer is the same for that question. I want a new way of doing it. I want to know an newer methods of doing it.
    – Kiran Tej
    Commented Nov 4, 2013 at 8:47

1 Answer 1


You should return your form using drupal_get_form in the content definition of your block. Drupal will do the rest.

For example like this:

function YOURMODULE_block_info()
    $blocks = array();

    $blocks['custom_block'] = array(
        'info' => t('Custom block example'),
        'title' => t('Custom block example'),
        'region' => 'content',
        'status' => 1,

    return $blocks;

function YOURMODULE_block_view($delta = '')
    $block = array();

    switch ($delta) {
        case 'custom_block' :
            $block['content'] = YOURMODULE_block_content();

    return $block;

function YOURMODULE_block_content()
    return drupal_get_form('my_custom_form');

function my_custom_form($form, &$form_state)
    // Build your form

    return $form
  • Yes, I tried this. Is there any other method to do this?
    – Kiran Tej
    Commented Nov 4, 2013 at 7:06
  • You also can directly call the drupal_render on the form and return it as #markup content for the block ... but you already tried ... which isn't working for you. Do you have some content of the block rendered on the page? (i.e.: the block wrapper html, title, ...) Commented Nov 4, 2013 at 12:22
  • Anyway as the requirement is urgent, I am using the old method. Thanks for your help.
    – Kiran Tej
    Commented Nov 5, 2013 at 4:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.