I have an ajax callback function:
function mymodule_callback($form, &$form_state) {
$nid = $form_state['build_info']['args'][0]->nid;
$node = node_load($nid);
module_load_include('inc', 'node', 'node.pages');
$form = node_page_edit($node);
return print_r($form, true);
}
(Please note that I'm returning from print_r as I'm trying to debug the problem).
This callback is being run from a form submit:
function mymodule_form_{my_form_id}_alter(&$form, &$form_state, $form_id) {
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => 'save',
'#ajax' => array(
'wrapper' => 'my-form-id',
'method' => 'replace',
'callback' => 'mymodule_callback',
'effect' => 'fade'
),
'#submit' => array('node_form_submit'),
);
}
When I submit the form I get an AJAX error which says 'cannot unset string offsets' in field.default.inc. I know that the node_page_edit function is causing it because when I remove it the error doesn't happen.
Interestingly, if I press the submit button again straight after getting this error, it works - and the full structure of the form is loaded in to my div.
Why doesn't it work the first time and how do I fix it?