Ahah helper appears to cause drupal to lose all new form values below the last ahah action. For instance in this code. Filling all three fields out in order and then clicking submit causes a validation error that the last field is missing.

function application_form_page1($form_state) {
  ahah_helper_register($form, $form_state);

  $form['Name'] = array(
    '#type' => 'fieldset',
    '#title' => t('Name'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['Name']['preferred'] = array(
    '#type' => 'textfield',
    '#title' => t('Preferred Name or Nickname'),
    '#default_value' => $form_state['values']['preferred'],
    '#description' => "The name you would like us to refer to you by. For example, <em>Bob</em> if your first name is <em>Robert</em>.",
    '#maxlength' => 20,
  '#size' => 20,
  );

// Birthplace Information
  $form['Birthplace_Information'] = array(
    '#type' => 'fieldset',
    '#title' => t('Birthplace Information'),
    '#prefix' => '<div id="birthplace-information-wrapper">', // This is our wrapper div.
    '#suffix' => '</div>',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['Birthplace_Information']['countryofbirth'] = array(
    '#type' => 'select',
    '#title' => t('Country of Birth'),
    '#default_value' => $form_state['values']['countryofbirth'],
    '#options' => array('' => '', 'a' => 'Somewhere', b => 'somewhere else'),
   '#ahah' => array(
     'path' => ahah_helper_path(array('Birthplace_Information')),
     'wrapper' => 'birthplace-information-wrapper',
     'method' => 'replace',
     'event' => 'change',
     'effect' => 'fade',
    ),
    '#required' => TRUE,
  );
  $form['Birthplace_Information']['update_countryofbirth'] = array(
    '#type' => 'submit',
    '#value' => t('Country of Birth'),
    '#submit' => array('ahah_helper_generic_submit'),
    '#attributes' => array('class' => 'no-js'),
  );

    $form['Birthplace_Information']['cityofbirth'] = array(
      '#type' => 'textfield',
      '#title' => t('City of Birth'),
      '#default_value' => $form_state['values']['cityofbirth'],
      '#required' => TRUE,
      '#maxlength' => 35,
      '#size' => 35,
    );
  $form['Submit'] = array(
  '#type' => 'submit',
  '#value' => t('Save and Continue'),
  );
  return ($form);

}

Comments

antgiant’s picture

On further investigation this bug appears to prevent any updates from saving after the ahah action. However, a new ahah action will save the values. Any help would be greatly appreciated.

antgiant’s picture

Priority: Normal » Critical

On further investigation I have isolated the bug to line 128 of ahah_helper.module.

  // We *do* save the form to the cache, so modules that use "D6 core style"
  // AHAH updates still work.
  form_set_cache($form_build_id, $form, $form_state);

It turns out that caching the form after the #values have been set causes drupal to not update them on the next load (form.inc line 980), thus all updates are lost. I'm not quite sure the correct fix to this. I think core avoids it by loading the form twice. The second time without values and caches the second load. I hope this helps in resolving the bug.

wim leers’s picture

Assigned: Unassigned » wim leers
Status: Active » Fixed

In version 2, I'm using the new Drupal core style approach. So this should not happen there. I must add that I never managed to get corrupt forms with version 1 either. But in version 2 it should be impossible.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.