Hola,

PROBLEM:
I've been working on a simple block module in which I seek to implement a form. My idea has been to set the $block_content to the form but unfortunately to no avail.Currently, using my code gives a 'page not found'. However, the block displays when I set $block_content to any string. A sample of my hook_block() code is as below:

  function loancal_block($op ='list',$delta=0,$edit=array()){
    if($op == 'list'){
     $block = array();
     $block[0]['info'] = t('Loan Calculator');
    return $block;
    }
 
    if($op == 'view'){
    $block['subject'] = t('Loan Calculator');
    $block['content'] = _loancal_test_form();
    return $block;
    }
 }

 function _loancal_test_form(){
    $form = array();
    $form['calculate']=array(
    '#type'=>'textfield',
    '#title'=>t('Enter amount'),
 '#size'=>15,
    'required'=>TRUE
    );
    $form['submit'] =array(
    '#type'=>'submit',
    '#value'=>t('Calculate')
    );
    return drupal_get_form('_loancal_test_form',$form);
   }

 function _loancal_test_form_submit($form,$form_state){
   $message = "Now u have a form in the block!";
   drupal_set_message($message);
   } 

QUESTION:
Is it possible to get this done in drupal 6 ? ..and what is the bug in my code that is causing what I'm experiencing.Any lead is deeply appreciated.

Regards,
Polarsky.

Comments

nevets’s picture

Try replacing $block['content'] = _loancal_test_form(); with $block['content'] = drupal_get_form('_loancal_test_form',$form);(); and having _loancal_test_form() return $form.

polarsky’s picture

Nevets,
Really sorry for my late response...was slightly indisposed.Thanks for your response .However, after doing what you suggested, it's still not working.I rather have this error in my webpage:
Fatal error: Unsupported operand types in /var/www/drupal6/includes/common.inc on line 2877
I know this means I'm not doing something right. or do I have to do some theming in the module to get the block to display..?
Regards,
Polarsky.

nevets’s picture

Typo on my part, drupal_get_form('_loancal_test_form',$form);(); should have been drupal_get_form('_loancal_test_form');

nikosnikos’s picture

Thanks ! It work for me.