Enabling module throws this error on every page:

Notice: Undefined index: #type in template_preprocess_search_block_form() (line 1072 of ...../drupal-7.0/modules/search/search.module).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jdanthinne’s picture

I just did a fresh D7 final install and enabled Custom Search module and sub-modules (latest DEV version), but I don't get any notice.
Which Custom Search modules have you installed, and what how have you configured it?

iplaw’s picture

FYI, the issue seems to only appear when I am logged out (i.e. anonymous user).

I have installed: Custom Search, Custom Search Blocks, Custom Search Internationalization, Custom Search Taxonomy.

I have enabled custom search.

:::Permissions:::
Custom Search
Administer Custom Search- Only Administrator Checked
Use Custom Search - All checked

Search
Administer Custom Search- Only Administrator Checked
Use Search - All checked
Use Advanced Search - All checked

:::Configure:::
Display label - [unchecked]
Search Box Label - [blank]
Search Box Default text - "search"

jdanthinne’s picture

Status: Active » Needs review
FileSize
1.34 KB

I've found the problem, some changes between Drupal 6 and 7 that I haven't noticed…
Please try this patch or download dev release (from 11th January).

iplaw’s picture

Status: Needs review » Reviewed & tested by the community

The patch fixes the problem. I also tried the DEV release from 12th Jan. which corrects the problem as well.

iplaw’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

joostvdl’s picture

Status: Closed (fixed) » Active

With the i18n Module enabled, this error re-occurs.

Notice: Undefined index: #type in template_preprocess_search_block_form() (regel 1070 van /Users/joost/Developer/gitrepos/rembrandt/modules/search/search.module).
joostvdl’s picture

Version: 7.x-1.6 » 7.x-1.x-dev
joostvdl’s picture

Status: Active » Closed (fixed)

Issue fixed in i18n module: #1092966: common search error in core

carl.ben’s picture

Status: Closed (fixed) » Active

This notice appears sporadically, on a variety of pages:

Notice: Undefined index: #type in template_preprocess_search_block_form() (line 1070 of .../modules/search/search.module).

Using 7.x-1.x-dev (10/20/11)

NOT using Custom Search blocks, or any other CS submodule. And no i18n.

Anon and Authenticated both have permission to use custom search, per comment #36 at http://drupal.org/node/1092966

yareckon’s picture

Am also getting this with only custom_search core module installed.

Aurochs’s picture

Version: 7.x-1.x-dev » 7.x-1.9

ш had same problem drupal 7.10 with honeypot antispam. i deselected the search fields from protection which helped me.

Anonymous’s picture

Well how odd. I had this problem as well (when as anonymous user only), but it went away right after I ran one search.

ClimbingUpTheWalls’s picture

I had the same problem but it's difficult to define which situations trigger this bug. Basically, it could happen on any page where there's a search form in the search block along with any other form. The problem seems to come from the search.module code here :

function template_preprocess_search_block_form(&$variables) {
$variables['search'] = array();
$hidden = array();
// Provide variables named after form keys so themers can print each element independently.
foreach (element_children($variables['form']) as $key) {
$type = $variables['form'][$key]['#type'];

For some reason, some form elements do not always have types for example on a text field edit? element so I temporarily added this instead :

if(isset($variables['form'][$key]['#type'])){
$type = $variables['form'][$key]['#type'];
}else{
$type = 'hidden';
}

but I don't think it's a good way to avoid this bug... Maybe someone else has a better idea?

chefnelone’s picture

I have the same error message:

Notice: Undefined index: #type en template_preprocess_search_block_form() (line 1070 de /myurl/modules/search/search.module).

FanisTsiros’s picture

Hmm, there is also another issue here #1543888: Notice: Undefined index: #type in template_preprocess_search_block_form() (line 1070 of drupal-7.12/modules/search/search.module

Well, i'm not sure if this is related to my case, also i am not using this module, but this could help:

I had the same issue, starting after i made a custom module and making some "form_alter" trying to hide the "Home Page" field in comments for anonymous users.

function mycustommodule_form_alter(&$form, &$form_state, $form_id) {
    $form['author']['homepage']['#access'] = FALSE; //hide home page comment field for all users
}

Notice was visible only for administrator. (anon have no permissions to search though). Search block was enabled for all pages.

i replaced above code using "hook_form_BASE_FORM_ID_alter" like this:

function mycustommodule_form_comment_form_alter(&$form, &$form_state, &$form_id) {
  $form['author']['homepage']['#access'] = FALSE; 
}

and the Notice have gone away...

jdanthinne’s picture

Version: 7.x-1.9 » 7.x-1.x-dev
Status: Active » Postponed (maintainer needs more info)

Can someone find a way to reproduce this bug with the latest DEV? I never get those notices…

Hammad.Chishti’s picture

Hello Guys,

Actually this bug is not related to the search module,I have test it multiple times.
So the problem is whenever in form alter i missed some array index or the index not defined in a array this error shows only in the page where my custom hook_form_alter calls my custom function.
Eventually because of the search form or block is on the top of a page and calls before the other block or whatever It shows the notice in search module because of the wrong array set.
Hope it helps to someone :)

thanks

schlicki’s picture

It looks like an access problem to me.
Debugging some arrays gave me some insight.
the template_preprocess_search_block_form function does not check accessability of fields it traverses. Maybe this is not the only problem here.
But checking for the '#type' key might not be the proper solution. Better check for accessability with

if (array_key_exists('#access', $variables['form'][$key]) && !$variables['form'][$key]['#access']) continue;

inside the loop in line 1070 of search.module (v7.12).
Hope that helps somehow ;)

J

adellefrank’s picture

I was not using the custom search module, just the basic one in core. I encountered this error after adding a hook_form_alter() to my template.php which tried to alter all forms (and, unknowingly, included the basic 'search_block_form' I was using). To "fix" this error, I made sure the first line of my if statement did NOTHING if the $form_id == 'search_block_form'. For example:

function MYTHEMENAME_form_alter(&$form, $form_state, $form_id) {

    global $user;

    if ($form_id == 'search_block_form') {
        
    } else {
        if (in_array('anonymous user', $user->roles)) {
            $form['revision_information']['#access'] = FALSE;
        } else {
            $form['revision_information']['#access'] = TRUE;
        }
    }
}
sunchaser’s picture

fix #20 did it for me thanx

jdanthinne’s picture

This has nothing to do with custom search then?

adellefrank’s picture

It looks like this has more to do with customized themes or modules using hook_form_alter().

jdanthinne’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
acouch’s picture

FileSize
147.1 KB

Still experiencing the same issue. Occurs when no content types are selected in the content tab. Would be great if it didn't leave that message since distros like Commons use this so it would be better in some instances to just disable them instead of the whole module.

jdanthinne’s picture

@acouch: just did a clean install of Drupal 7.22 and Custom Search 1.12, didn't select any content type in the content tab, checked the "Force -Any- to be displayed", and performed a search: no errors… Do you use a custom theme? Does this bug happen if you switch to a core theme (Bartik)? Do you have a test url?

jdanthinne’s picture

@acouch: small update on your issue… I've installed Commons in order to see what's wrong with Custom Search + Commons.
And it seems that they're trying to override Custom Search with one of their module (commons_search) by overriding the search form instead of using the hook I'm invoking to work with other search modules (hook_search_info).
I think this issue is related to Drupal Commons, and you should open issue in the Commons project page to resolve this (and I'd be happy to work with them if needed).

xurizaemon’s picture

This is a 7.x-1.x issue, but the fix for 6.x-1.x seems to be to remove line 315. AFAICT there's no need for this module to add an additional FAPI item for the form token, and if added we were seeing this issue (for anonymous users only).

The following code can be removed from 6.x-1.x.

        $form['form_token']['#default_value'] = drupal_get_token($form_id);
xurizaemon’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Issue summary: View changes
Status: Closed (cannot reproduce) » Needs review
FileSize
704 bytes

Since I'm here ... and this is can't repro for 7.x-1.x ... I'll post a patch for 6.x-1.x.