1

I have a menu callback, and I want to add a form on it using the following code.

function parking_calculator_menu() {
  $items['admin/parkingcalculator'] = array(
    'title' => 'Node parkingCalculator',
    'description' => 'Adjust node parkingCalculator options.',
    'position' => 'right',
    'weight' => -5,
    'page callback' => 'get_form',
    'access arguments' => array('administer site configuration'),
  );

  return $items;
}

function get_form() {
  $form['short-term-parking'] = array(
    '#title' => t('Short term parking'),
    '#type' => 'fieldset',
    '#description' => t('Short term parking.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  $form['short-term-parking']['free_time'] = array(
    '#type' => 'textfield',
    '#required' => TRUE, 
    '#title' => t('Free time'),
    '#default_value' => variable_get('free_time', 1),
    '#description' => t('Please enter Free time.')
  );

  $form['short-term-parking']['long-term-starts'] = array(
    '#title' => t('Long term starts'),
    '#type' => 'textfield',
    '#default_value' => variable_get('long-term-starts', 1),
    '#required' => TRUE, 
    '#description' => t('Please enter Long term starts.')
  );

  $form['short-term-parking']['first-hour-cost'] = array(
    '#title' => t('First hour cost'),
    '#type' => 'textfield',
    '#default_value' => variable_get('first-hour-cost', 1),
    '#required' => TRUE, 
    '#description' => t('Please enter First hour cost.')
  );

  $form['short-term-parking']['each-hour-cost'] = array(
    '#title' => t('Each hour cost'),
    '#type' => 'textfield',
    '#default_value' => variable_get('each-hour-cost', 1),
    '#required' => TRUE, 
    '#description' => t('Please enter Each hour cost.')
  );

  $form['long-term-parking'] = array(
    '#title' => t('Long term parking'),
    '#type' => 'fieldset',
    '#description' => t('Long term parking.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE
  );

  $form['long-term-parking']['free_timel'] = array(
    '#type' => 'textfield',
    '#required' => TRUE, 
    '#default_value' => variable_get('free_timel', 1),
    '#title' => t('Free time'),
    '#description' => t('Please enter Free time.')
  );

  $form['long-term-parking']['long-term-startsl'] = array(
    '#title' => t('Long term starts'),
    '#default_value' => variable_get('long-term-startsl', 1),   
    '#type' => 'textfield',
    '#required' => TRUE, 
    '#description' => t('Please enter Long term starts.')
  );

  $form['long-term-parking']['first-hour-costl'] = array(
    '#title' => t('First hour cost'),
    '#type' => 'textfield',
    '#default_value' => variable_get('first-hour-costl', 1),
    '#required' => TRUE, 
    '#description' => t('Please enter First hour cost.')
  );

  $form['long-term-parking']['each-hour-costl'] = array(
    '#title' => t('Each hour cost'),
    '#type' => 'textfield',
    '#default_value' => variable_get('each-hour-costl', 1),
    '#required' => TRUE, 
    '#description' => t('Please enter Each hour cost.')
  );

  $form['valet-parking'] = array(
    '#title' => t('Valet parking'),
    '#type' => 'fieldset',
    '#description' => t('Valet parking.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE
  );

  $form['valet-parking']['first-hour-costv'] = array(
    '#title' => t('First hour cost'),
    '#type' => 'textfield',
    '#default_value' => variable_get('first-hour-costv', 1),
    '#required' => TRUE, 
    '#description' => t('Please enter First hour cost.')
  );

  $form['valet-parking']['each-hour-costv'] = array(
    '#title' => t('Each hour cost'),
    '#type' => 'textfield',
    '#default_value' => variable_get('each-hour-costv', 1),
    '#required' => TRUE, 
    '#description' => t('Please enter Each hour cost.')
  );

  return system_settings_form($form);
}

With this code, I get the following error message:

Recoverable fatal error: Argument 1 passed to drupal_attributes() must be an array, null given, called in /var/www/html/APIG01JO2012039/includes/form.inc on line 3252 and defined in drupal_attributes() (line 2366 of /var/www/html/APIG01JO2012039/includes/common.inc). The website encountered an unexpected error. Please try again later.

Why am I getting that error?

1

The page arguments hook_menu() expects is an array, not a string.

function parking_calculator_menu() {
  $items['admin/parkingcalculator'] = array(
    'title' => 'Node parkingCalculator',
    'description' => 'Adjust node parkingCalculator options.',
    'position' => 'right',
    'weight' => -5,
    'page callback' => 'drupal_get_form',
    // You used:
    // 'page callback' => 'get_form',
    // The correct value is the following one:
    'page arguments' => array('get_form'),
    'access arguments' => array('administer site configuration'),
  );

  return $items;
}

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.