I can not save fields changed by Ajax in Drupal

0

I have a problem with dropdown lists that are dependent, when I select a change the second and then the third, until here works well, the problem is when I try to save these values in their respective table of each field but not guard. I have the hook for the form to update a profile:

function mytheme_form_profile2_edit_candidata_form_alter(&$form, &$form_state) {

  drupal_add_library('system', 'ui.datepicker');

  $form['profile_candidata']['field_candidata_cedula']['und'][0]['value']['#description'] = 'Ingresa sólo números';

  $vocabulary = taxonomy_vocabulary_machine_name_load('field_candidata_lugar_postul');
  $taxonomy_tree = taxonomy_get_tree($vocabulary->vid, 0, 1);
  $dpt = array();
  $dpt[0] = '-Elige-';
  foreach ($taxonomy_tree as $key => $term) {
    $dpt[$term->tid] = $term->name;
  }
  $form['profile_candidata']['field_candidata_lugar_postul']['und']['#options'] = $dpt;
  $form['profile_candidata']['field_candidata_lugar_postul']['und']['#validated'] = TRUE;

  if( !is_null($form['profile_candidata']['field_candidata_lugar_postul']['und']['#default_value'][0]['tid']) ) {

    $vocabulary = taxonomy_vocabulary_machine_name_load('field_candidata_lugar_postul');
    $vld = $form['profile_candidata']['field_candidata_lugar_postul']['und']['#default_value'][0];
    $taxonomy_tree = taxonomy_get_tree($vocabulary->vid, $vld, 1);

    $opt_c = array();
    $opt_c[0] = '-Elige-';
    foreach ($taxonomy_tree as $key => $term) {
      $opt_c[$term->tid] = $term->name;
    }

    $form['profile_candidata']['field_candidata_lugar_postul_c']['und']['#options'] = $opt_c;
    $default_city = $form['profile_candidata']['field_candidata_lugar_postul_c']['und']['#default_value'][0];
    $form['profile_candidata']['field_candidata_lugar_postul_c']['und']['#default_value'] = $default_city;

  } else {

    $form['profile_candidata']['field_candidata_lugar_postul_c']['und']['#options'] = array(
      '' => '-Elige un departamento-'
    );

  }

  $form['profile_candidata']['field_candidata_lugar_postul']['und']['#ajax'] = array(
    // Wrapper set in $form['location']
    'wrapper' => 'res_candidata_lugar_postul_c',
    // Callback function to be shown later
    'callback' => 'load_cities_callback',
    'event' => 'change'
  );

  $form['profile_candidata']['field_candidata_lugar_postul_c']['und']['#prefix'] = '<div id="res_candidata_lugar_postul_c">';
  $form['profile_candidata']['field_candidata_lugar_postul_c']['und']['#suffix'] = '</div>';
  $form['profile_candidata']['field_candidata_lugar_postul_c']['und']['#validated'] = TRUE;

  $form['profile_candidata']['field_candidata_lugar_postul_c']['und']['#ajax'] = array(
    // Wrapper set in $form['location']
    'wrapper' => 'res_candidata_lugar_postul_s',
    // Callback function to be shown later
    'callback' => 'load_sectors_callback',
    'method' => 'replace',
  );

  $form['profile_candidata']['field_candidata_lugar_postul_s']['und']['#prefix'] = '<div id="res_candidata_lugar_postul_s">';
  $form['profile_candidata']['field_candidata_lugar_postul_s']['und']['#suffix'] = '</div>';
  $form['profile_candidata']['field_candidata_lugar_postul_s']['und']['#validated'] = TRUE;

  if( !is_null($default_city) ) {

    $vocabulary = taxonomy_vocabulary_machine_name_load('field_candidata_lugar_postul');
    $vld = $default_city;
    $taxonomy_tree = taxonomy_get_tree($vocabulary->vid, $vld, 1);

    $opt_s = array();
    if(count($taxonomy_tree)>0) {

      $opt_s[0] = '-Elige-';
      foreach ($taxonomy_tree as $key => $term) {
        $opt_s[$term->tid] = $term->name;
      }

    } else {

      $opt_s[0] = '-No aplica-';

    }

    $form['profile_candidata']['field_candidata_lugar_postul_s']['und']['#options'] = $opt_s;

  } else {

    $form['profile_candidata']['field_candidata_lugar_postul_s']['und']['#options'] = array(
      '' => '-Elige una ciudad-'
    );

  }

  $form['#after_build'] = array('mmmd_set_form_uidatepicker');

}

Although I have the Field Permissions module installed, it has Public permission to discard if it does not save. I really do not know if I have something in the wrongly formulated code or why it does not save this field, I currently have not altered the behavior of the submit for this form. I appreciate the help on this topic.

    
asked by josotoru 12.03.2018 в 15:15
source

0 answers