6

I don't usually post specific questions like this, and ask for help on a specific issue but I am at the end of my rope wasting time way...

I have a simple D7 module as seen below, when I load the page (who's menu item is exactly where I want it to be) I get the following error:

Recoverable fatal error: Argument 1 passed to drupal_attributes() must be an array, null given, called in /path/to/site/public_html/includes/form.inc on line 3106 and defined in drupal_attributes() (line 2257 of /path/to/site/public_html/includes/common.inc).

as you can see the form declaration itself is very simple, and everything runs peachy keen until the page load.

note, that I have looked at: 3106 in form.inc and the $element is populated but attributes doesn't exist - what am I missing???

<?php
/**
 * Implements hook_menu().
 */
function attach_images_menu() {

    $items['admin/structure/types/manage/%/attach/images'] = array(
        'title' => 'Attach: Images',
        'page callback' => 'attach_images_settings',
        'access arguments' => array('access administration pages'),
        'weight' => '10',
        'type' => MENU_LOCAL_TASK,
    );

    return $items;

}

function attach_images_settings() {
    //$content_type = arg(4);
    $form['attach_images_amount_'] = array(
         '#type'   => 'textfield',
         '#title'  => 'Amount',
         '#default_value' => variable_get('attach_images_amount_',1),
    );
  return system_settings_form($form);
}

?>
12
$items['admin/structure/types/manage/%/attach/images'] = array(
    'title' => 'Attach: Images',
    'page callback' => 'attach_images_settings',
    'access arguments' => array('access administration pages'),
    'weight' => '10',
    'type' => MENU_LOCAL_TASK,
);

This should be 'page callback' => 'drupal_get_form', 'page arguments' => array('attach_images_settings'). (don't forget to clean the cache after making the change)

Also, form callbacks in Drupal 7 have a mandatory $form argument.

  • it takes a village to train a drupal dev... I can't believe I forgot that - let me verify you >> me – electblake Mar 17 '11 at 2:05
  • yeah you're (obviously) right, figures. You just get so focused on other things you forget these simple things.... Thanks! – electblake Mar 17 '11 at 2:06
  • Damien Tournoud cannot be wrong. – kiamlaluno Mar 17 '11 at 15:50
3

It's worth remembering that specifying 'drupal_get_form' in your page callback is no different than implementing your own custom built-from-scratch page callback, and calling drupal_get_form() in it.

  • 1
    Except if you use your own "built-from-scratch" page callback then you'll have a far easier time adding any design elements or markup to the page (rather then adding it to the $form, which always gets weird for me) – electblake Mar 18 '11 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.