[development] Adding Form In Block With hook_block()

Steve Edwards killshot91 at comcast.net
Tue May 20 20:48:02 UTC 2008


I didn't get any bites on this one on the support list, so I'm hoping 
some of you development gurus can help me.

I would like to add a simple area calculator form (length x width x 
depth = area) to a sidebar block, and I'm having problems figuring how 
to get the form to show up in the block using hook_block().  I've gotten 
the block to show up in the blocks list and have enabled it, but I can't 
get it to show up.  I've been using the blocks chapter in the PDD book 
as a guideline, but I must be missing something.

Here's what I have so far.

<?php

function calculate_square_form() {
    $form['length'] = array(
        '#title' => t('Length'),
        '#type' => 'textfield',
        );
       
    $form['width'] = array(
        '#title' => t('Width'),
        '#type' => 'textfield',
        );       

    $form['depth'] = array(
        '#title' => t('Depth'),
        '#type' => 'textfield',
        );
       
    $form['depth'] = array(
        '#title' => t('Area'),
        '#type' => 'textfield',
        );

    $form['length'] = array(
        '#type' => 'button',
        '#value' => t('Calculate area')
        );
}       

function shbark_calculate_block($op = 'list', $delta = 0, $edit = array()) {
    switch ($op) {
        case 'list':
            $blocks[0]['info'] = t('Square area calculator');
            return $blocks;
           
        case 'view':
            $block['subject'] = t('Area calcultor');
            drupal_get_form('calculate_square_form');
            break;
    }
}
    
How do I get my block content to be displayed?  Do I have to pass the 
form to a theme function?  Do I assign the form data to 
$block['content'] somehow?  Or do I have to put the form array in the 
'view' case for $op instead of a separate form function?

Thanks.

Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20080520/2b4e0f97/attachment.htm 


More information about the development mailing list