I'm using hook_form_alter to alter search block form (actualy i need to add a adv. search link. So i decidet to use markup element

    $form['ad_search'] = array(
        '#markup' => l('advanced search','search/node'),
        '#weight' => 1000,

As mentioned in api: http://api.drupal.org/api/drupal/developer%21topics%21forms_api_referenc...


Description: Generate generic markup for display inside forms. Note that there is no need to declare a form element as #type = 'markup', as this is the default type.

But search module produce a notice:

Notice: Undefined index: #type in function template_preprocess_search_block_form() (line 1070 in file /var/www/rating.local/modules/search/search.module).

I believe that line 1070

$type = $variables['form'][$key]['#type'];

must be changed to

$type = empty($variables['form'][$key]['#type']) ? 'markup' : $variables['form'][$key]['#type'];
#4 drupal7x-search-block-undefined-index-1928690.patch1.03 KBovi.indrei
PASSED: [[SimpleTest]]: [MySQL] 40,442 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


marcingy’s picture

Status: Active » Closed (works as designed)
Heine’s picture

Status: Closed (works as designed) » Active

#markup is a valid property of #type markup and #type item elements.

So, either http://api.drupal.org/api/drupal/developer%21topics%21forms_api_referenc... is wrong, or there's a bug in form handling, where the default #type is not assigned.

yark’s picture

Not "should be" but "may be".

See example at that page uder markup section, not #markup:

$form['contact_information'] = array(

  '#markup' => variable_get('contact_form_information',
t('You can leave us a message using the contact form


When i alter add node form and adding markup fields all works without any notice:

ovi.indrei’s picture

Title: Assuming, that #type will be not empty always » Search block template: Undefined index: #type
Version: 7.20 » 7.x-dev
Assigned: Unassigned » ovi.indrei
Status: Active » Needs review
1.03 KB
PASSED: [[SimpleTest]]: [MySQL] 40,442 pass(es). View

Here's a quick patch that fixes the issue. Please test and confirm that is fixed. Thanks.

yark’s picture

Works for me. But i still belive that we need to assign 'markup' insead empty string. May be sometime later it needs to add special case for 'markup' as it done to hidden and token now.

includes/common.inc 5803..5807

  // If #markup is set, ensure #type is set. This allows to specify just #markup
  // on an element without setting #type.
  if (isset($elements['#markup']) && !isset($elements['#type'])) {
    $elements['#type'] = 'markup';
ovi.indrei’s picture

The hidden and token Form API #types are both hidden form fields and this is basically the reason why they get treated different than the rest of the fields. So I really don't think the markup element will ever get treated the same as the other hidden elements.

ovi.indrei’s picture

Status: Needs review » Reviewed & tested by the community

Seems like nobody has anything else to add. Since this is a trivial fix, already confirmed to work, I'll push this issue to the next step. Feel free to intervene though, if you think it's the case.

marcingy’s picture

Status: Reviewed & tested by the community » Needs review

You can't RTBC your own patches.

hazem.tamimi’s picture

ovi.indrei’s picture

@marcingy, I know, I read the documentation, but I considered this to be the exception, because it's a very trivial fix.
Besides, @yark confirmed it is working. I thought things are supposed to move quicker with these quick fixes. Any feedback is welcomed.

michaelmol’s picture

Status: Needs review » Reviewed & tested by the community

I ran into the same issue and can confirm the error isn't showing anymore.

ovi.indrei’s picture

kozmik’s picture

Had the same issue, can confirm that patch #4 resolves it without any other implications.
@ovidyou: thanks a ton!

ovi.indrei’s picture

ovi.indrei’s picture

Assigned: ovi.indrei » Unassigned
malcomio’s picture

patch #4 works fine for me too

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks! http://drupalcode.org/project/drupal.git/commit/af8d800

(And I confirmed that this doesn't appear to be an issue in Drupal 8.)

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