I am writing a form using the Drupal 7 form API. On submitting the form (via AJAX), the following error is displayed:
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /en/system/ajax StatusText: Internal Server Error ResponseText: Recoverable fatal error: Argument 1 passed to drupal_array_nested_key_exists() must be an array, null given, called in /drupal7/includes/form.inc on line 1986 and defined in drupal_array_nested_key_exists() (line 6296 of /drupal7/includes/common.inc).
I have two buttons on the form (copy & submit); one is an AJAX call which does some stuff, and the other is used to save the entered data.
This is the code I'm using:
function foo_form ($form, &$form_state, $foo) {
$form['#foo'] = $foo;
$form_state['values'] = $foo;
$form['#prefix'] = '<div id="foo-form-wrapper">';
$form['#suffix'] = '</div>';
$form['copy'] = array(
'#type' => 'submit',
'#value' => t('Copy foo'),
'#limit_validation_errors' => array(),
'#submit' => array('foo_form_submit'),
'#ajax' => array(
'wrapper' => 'foo-form-wrapper',
'callback' => 'foo_form_callback',
),
);
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#required' => TRUE,
'#maxlength' => 255,
'#default_value' => (!isset($form_state['values']['name']) ? $foo->name : $form_state['values']['name']),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function foo_form_callback($form, $form_state) {
return $form;
}
function foo_form_submit ($form, &$form_state) {
// Did we use the AJAX Call?
// @todo: can we check this some other way?
if (!isset($form_state['triggering_element']['#ajax'])) {
// We didn't, save the entered values
$form_state['rebuild'] = false;
return;
} else {
// We did, do some behind the scenes stuff...
$form_state['rebuild'] = true;
}
}
Does anyone have an idea of what could be wrong?