0

I am just starting out making my module and already running into 2 problems, I believe this is being cause because the form is in a block but I am not entirely sure. This is what I have in my .module file, as you can see I have the function to output the drupal message upon submission however it simply does not do anything. I also get this error when I have the variables in my function.

Notice: Undefined variable: form in zillow_block_view() (line 33 

and

Deprecated function: Call-time pass-by-reference has been deprecated in drupal_load() (line 933 of C:\xampp\htdocs\drupal\includes\bootstrap.inc).

function zillow_block_info(){ $blocks['zillow_block'] = array( 'info' => t('Zillow Block'), ); return $blocks; }

function zillow_block_view($delta = ''){
    $block = array();
        switch ($delta){
    case 'zillow_block';
        $block['subject'] = t('Zillow Block');
        $block['content'] = zillow_form($form, &$zinfo);
    break;
    }
    return $block;
}

function zillow_form($form, &$zinfo){

    $form['description'] = array(
        '#type' => 'item',
        '#title' => t('Get your mortgage rates'),
    );
    $form['rates'] = array(
        '#type' => 'fieldset',
        '#title' => t('Mortgage Rates'),
        '#collapsiable' => TRUE,
        '#collapsed' => FALSE,
    );
    $form['rates']['street'] = array(
        '#type' => 'textfield',
        '#title' => t('Street Address'),
        '#default_value' => 'Street Address',
    );
    $form['rates']['city'] = array(
        '#type' => 'textfield',
        '#title' => t('City'),
        '#default_value' => 'City',
    );
    $form['rates']['zip'] = array(
        '#type' => 'textfield',
        '#title' => t('Zip Code'),
        '#required' => TRUE,
        '#default_value' => "Zip Code",
        '#description' => 'Please enter your zip code',
        '#size' => 5,
        '#maxlength' => 5,
    );  
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Submit',
    );
    return $form;
}

function zillow_submit_info($form, &$zinfo){
        drupal_set_message('this is the info the form has submitted. zipcode=@zipcode',
        array('@zipcode'=>$zinfo['values']['zip']));
    }

any help is appreciated.

2 Answers 2

2

Do not call form builder functions directly. Retrieve the form with

$block['content'] = drupal_get_form('zillow_form');

drupal_get_form() is the entry point into much of the magic that the Forms API does, like building, validating, invoking submit callbacks and (in Drupal 6) rendering. If you do not call it, you have to replicate much of what drupal_get_form() does in your own code, which is not a good idea.

Also, as Joe Beuckman noted, the submit callback should be called zillow_form_submit.

2

This line is using the deprecated pass-by-reference:

    $block['content'] = zillow_form($form, &$zinfo);

You can fix that with no ampersand:

    $block['content'] = zillow_form($form, $zinfo);

And I think your submit function should be named zillow_form_submit instead of zillow_submit_info.

1
  • thanks, but it still does not submit, its acting like a button with nothing on it Commented Mar 15, 2012 at 1:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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