Domanda

I'm trying to build a custom module that has to add a form to the sidebar_first. I tried using page_build hook but that did not work.

function module1_page_build(&$page){
     drupal_set_message("Inside page builder");
     $page['sidebar_first']['filters'] = array(
        '#markup' => drupal_form_build('filter_formbuild',$formstate=NULL),
        '#prefix' => '<div class="filters">',
        '#suffix' => '</div>',
    );    
}

I created a function filter_formbuild which returns a form array which is something like this. function filter_formbuild(){

$form = array();    



$form['title'] = array(
    '#title' => 'Title',
    '#type' => 'textfield',
    '#size' => '100',
);

$form['url'] = array(
    '#title' => 'Name',
    '#type' => 'textfield',
    '#size' => '100',
);

$form['notes'] = array(
    '#title' => 'Notes',
    '#type' => 'textarea',
            '#maxlength' => 200, 
    '#size' => '30',
);

    $form['author'] = array(
    '#title' => 'Author(s)',
    '#type' => 'textfield',
            '#maxlength' => 30, 
    '#size' => '100',   
);

    $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',       
);



     return $form;
}

I think the hook was not initiated since the set_message was also not working. Can someone suggest another way to do this or is there any errors in my implementation. I'm new to drupal custom modules

È stato utile?

Soluzione

  • Create a block
/**
 * Implements hook_block_info().
 */
function custom_block_block_info() {
  $blocks = array();
  $blocks['my_block'] = array(
    'info' => t('My Custom Block'),
  );

  return $blocks;
}
  • Add a form to your custom block hook_block_view
  • Add your block to the sidebar_first
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top