I have a custom search block (nice module) on my Drupal site, but every time a page is loaded I'm getting the following error:
Notice: Undefined variable: forms in custom_search_blocks_forms() (line 120 of xxx\sites\all\modules\custom_search\modules\custom_search_blocks\custom_search_blocks.module).

When I look at that function I see that $forms will not be defined when there's nothing to loop through.

/**
 * Implements hook_forms(). Generates a unique form_id with the same form builder function
 */
function custom_search_blocks_forms($form_id, $args) {
  for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
    $forms['custom_search_blocks_form_' . $a] = array(
      'callback'            => 'custom_search_blocks_form',
      'callback arguments'  => array($a),
    );
  }
  return $forms;
}

I fixed it myself by defining $forms. Not that great in PHP though, so I don't know if this is the right way.

/**
 * Implements hook_forms(). Generates a unique form_id with the same form builder function
 */
function custom_search_blocks_forms($form_id, $args) {
  $forms = array();
  for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
    $forms['custom_search_blocks_form_' . $a] = array(
      'callback'            => 'custom_search_blocks_form',
      'callback arguments'  => array($a),
    );
  }
  return $forms;
}

Comments

jdanthinne’s picture

Status: Active » Fixed

Thanks. I've pushed the fix in DEV version.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.