Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
jdanthinne CreditAttribution: jdanthinne commentedThanks. I've pushed the fix in DEV version.