Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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;
}
share|improve this question
    
try putting $form_state['rebuild'] = TRUE; in courses_lists_form_ajax() function. –  Mathankumar Dec 15 '12 at 13:12
    
It didn't work. I also tried this solution; drupal.stackexchange.com/a/31298/11310, and had no luck, still get the errors on the second call. Thanks –  david ruiz Dec 15 '12 at 15:28
    
There was an error in the generated markup. A missing closing div was messing everything. Now everything work as expected. Thanks –  david ruiz Dec 16 '12 at 12:27
add comment

1 Answer

up vote 1 down vote accepted

There was an error in the generated markup. A missing closing div was messing everything. Now everything work as expected. Thanks.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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