Thanks for looking at this question....

I want to be able to display and form in a block when it's viewed. Is is possible to do this from a render array? If so, how can this be done.

Here's the function: -

function faq_search_block_view($delta = '') {
	$block = array();

	switch ($delta) {
		case 'faq_search':
      		$block['subject'] = t('FAQ Search');
                // I want to be able to something like this: -
      		$block['content'] = array(
    			'#type' => 'form', 
                        '#form' => 'faq_search_form',
      		);
      		break;
	}
	return $block;
}

function faq_search_form($form, &$form_state) { ....


Apologies if the documentation exists - I've tried looking for a while now but can't find out how.

Comments

ooXei1sh’s picture

/**
 * Implements hook_block_info().
 */
function myform_block_info() {
  $blocks['myform'] = array(
    'info'  => t('Custom form block'),
    'cache' => DRUPAL_CACHE_GLOBAL,
  );
  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function myform_block_view($delta='') {
  $block = array();
  switch ($delta) {
  case 'myform':
    $block['subject'] = t('Contact Us Today');
    $block['content'] = drupal_get_form('myform');
    break;
  }
  return $block;
}

/**
 * Form Builder Function
 */
function myform($form, &$form_state) {
  // form fields go here...
  return $form;
}
dubs’s picture

Perfect - thanks so much!

ShedPhotons’s picture

I needed this, too, and had trouble finding a proper example as well.

geocalleo’s picture

This is also what I was looking for. Much appreciated.

islalobo’s picture

Also wanted to say thanks! This was helpful!