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.
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).
Comment | File | Size | Author |
---|---|---|---|
#29 | custom_search-1016740-undefined_index_type_anonymous.patch | 704 bytes | xurizaemon |
#25 | custom_search_error.jpg.jpg | 147.1 KB | acouch |
#3 | blocks-d7.patch | 1.34 KB | jdanthinne |
Comments
Comment #1
jdanthinne CreditAttribution: jdanthinne commentedI 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?
Comment #2
iplaw CreditAttribution: iplaw commentedFYI, 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"
Comment #3
jdanthinne CreditAttribution: jdanthinne commentedI'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).
Comment #4
iplaw CreditAttribution: iplaw commentedThe patch fixes the problem. I also tried the DEV release from 12th Jan. which corrects the problem as well.
Comment #5
iplaw CreditAttribution: iplaw commentedComment #7
joostvdl CreditAttribution: joostvdl commentedWith the i18n Module enabled, this error re-occurs.
Comment #8
joostvdl CreditAttribution: joostvdl commentedComment #9
joostvdl CreditAttribution: joostvdl commentedIssue fixed in i18n module: #1092966: common search error in core
Comment #10
carl.ben CreditAttribution: carl.ben commentedThis 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
Comment #11
yareckon CreditAttribution: yareckon commentedAm also getting this with only custom_search core module installed.
Comment #12
Aurochs CreditAttribution: Aurochs commentedш had same problem drupal 7.10 with honeypot antispam. i deselected the search fields from protection which helped me.
Comment #13
Anonymous (not verified) CreditAttribution: Anonymous commentedWell how odd. I had this problem as well (when as anonymous user only), but it went away right after I ran one search.
Comment #14
ClimbingUpTheWalls CreditAttribution: ClimbingUpTheWalls commentedI 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?
Comment #15
chefnelone CreditAttribution: chefnelone commentedI have the same error message:
Notice: Undefined index: #type en template_preprocess_search_block_form() (line 1070 de /myurl/modules/search/search.module).
Comment #16
FanisTsiros CreditAttribution: FanisTsiros commentedHmm, 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.
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:
and the Notice have gone away...
Comment #17
jdanthinne CreditAttribution: jdanthinne commentedCan someone find a way to reproduce this bug with the latest DEV? I never get those notices…
Comment #18
Hammad.Chishti CreditAttribution: Hammad.Chishti commentedHello 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
Comment #19
schlicki CreditAttribution: schlicki commentedIt 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
inside the loop in line 1070 of search.module (v7.12).
Hope that helps somehow ;)
J
Comment #20
adellefrank CreditAttribution: adellefrank commentedI 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:
Comment #21
sunchaser CreditAttribution: sunchaser commentedfix #20 did it for me thanx
Comment #22
jdanthinne CreditAttribution: jdanthinne commentedThis has nothing to do with custom search then?
Comment #23
adellefrank CreditAttribution: adellefrank commentedIt looks like this has more to do with customized themes or modules using hook_form_alter().
Comment #24
jdanthinne CreditAttribution: jdanthinne commentedComment #25
acouch CreditAttribution: acouch commentedStill 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.
Comment #26
jdanthinne CreditAttribution: jdanthinne commented@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?
Comment #27
jdanthinne CreditAttribution: jdanthinne commented@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).
Comment #28
xurizaemonThis 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.
Comment #29
xurizaemonSince I'm here ... and this is can't repro for 7.x-1.x ... I'll post a patch for 6.x-1.x.