I have this simple ajax form with some ajax taxonomy checkboxes and a function that renders the content when the users changes the selected checkboxes. Everything work fine, the first time. The second time the user changes a checkbox I get this error:
Undefined index: form_build_id in ajax_get_form() (line 320 of /var/www/mf/includes/ajax.inc)
and Invalid form POST data.
The only strange thing I've seen is when I inspect the request, there are a settings command, and ok insert command and another empty insert:
{command:insert, method:prepend, selector:null, data:, settings:null}
And in my html there is an empty .
My form:
function courses_lists_form($form, &$form_state) {dd(date('l jS \of F Y h:i:s A'));
$terms = taxonomy_get_tree(1); // 1 = courses taxonomies vid
$terms_array = array();
foreach ($terms as $term) {
$terms_array[$term->tid] = $term->name;
}
$form['taxonomias'] = array(
'#type' => 'checkboxes',
'#options' => $terms_array,
'#title' => t('TEMÁTICAS'),
'#ajax' => array(
'callback' => 'courses_lists_form_ajax',
'wrapper' => 'courses-lists-ajax',
),
);
$form['block'] = array(
'#prefix' => '<div id="courses-lists-ajax">',
'#markup' => mf_form_commons_courses_lists_gen(0, 0, TRUE, 'matrix', array(0 => 9), ''),
'#suffix' => '</div>',
);
$form_state['redirect'] = FALSE;
return $form;
}
function courses_lists_form_ajax($form, &$form_state){
$taxs = array();
foreach ($form_state['values']['taxonomias'] as $tid) {
if($tid) $taxs[] = $tid;
};
$outp = '<div id="courses-lists-ajax">';
$outp .= mf_form_commons_courses_lists_gen(0, 0, TRUE, 'matrix', $taxs, '');
$outp .= '</div>';
return $outp;
}