I have tried to create a node with an AHAH helper module form, but when I choose the desired option in the select list ($form['education']['edulevel']) then the form elements dissapear. I think is a problem with $form_state, but I'm a Drupal starter and I don't know how to solve this. I'd thank any suggestion.


function idibay_profile_form(&$node) {

 
$type = node_get_types('type', $node);
 
  $form = array();
  ahah_helper_register($form, $form_state);

  if (
$type->has_title) {
    $form['title'] = array(
      '#type' => 'hidden',
      '#required' => TRUE,
      '#default_value' => $node->uid,
    );
  }

 
$form['education'] = array(
     '#type' => 'fieldset',
     '#title' => t('Education Data'),
     '#prefix' => '<div id="education-wrapper">', // This is wrapper div.
     '#suffix' => '</div>',
     '#tree' => TRUE,
   );   

 
$form['education']['edulevel'] = array(
     '#type' => 'select',
     '#title' => t('Education level'),
     //'#default_value' => isset($node->edulevel) ? $node->edulevel : '',  
     '#options' => array(
     '' => t('- Select -'),
     'Bachelor' => t('Bachelor'),
     'Master' => t('Master'),
     ),
     '#default_value' => $form_state['values']['education']['edulevel'],
     '#ahah' => array(
      'event' => 'change',
      'path' => ahah_helper_path(array('education')),
      'wrapper' => 'education-wrapper',
    ),
  ); 

 
$form['education']['update_edulevel'] = array(
    '#type' => 'submit',
    '#value' => t('Update education level'),
    '#submit' => array('ahah_helper_generic_submit'),
    '#attributes' => array('class' => 'no-js'),
  );   

  if (
$form_state['values']['education']['edulevel'] == 'Bachelor') {
    $form['education']['bachelor_name'] = array(
     '#type' => 'select',
     '#title' => t('Detailed education'),
     '#options' => array(
        '' => t('- Select -'),
        'bacmed' => t('Bachelor in Medicine'),
        'bacvet' => t('Bachelor in Veterinary'),
      ),
      '#default_value' => $form_state['values']['education']['bachelor_name'],
    );
  } else {
    $form['education']['master_name'] = array(
        '#type' => 'select',
        '#title' => t('Detailed education'),
        '#options' => array(
        '' => t('- Select -'),
        'masbiof' => t('Master in Biochemistry'),
        'maschem' => t('Master in Chemistry'),
         ),
         '#default_value' => $form_state['values']['education']['master_name'],
    );   
  }

  return
$form;
}

Comments

oligoelemento’s picture

Status: Active » Closed (duplicate)

Sorry by my impatience. This issue is duplicated: http://drupal.org/node/328201