Support

Account

Home Forums ACF PRO Problems with group fields (when saving profile data) Reply To: Problems with group fields (when saving profile data)

  • Thank you so much for responding, John.

    I believe we’re talking about slightly different things.

    Let me share some code with you.

    $fields_goals = array(
        'ryit_user_legacy_vision', //vision
        'ryit_user_legacy_mission', //mission
        'ryit_user_goals_ten_year', //ten year goal
        'ryit_user_goals_five_year', //five year goal
        'ryit_user_goals_one_year' //one-year goal
      );
    
      $fields_interests = array(
        'ryit_user_interests_expertise', //fields of interest or skill
        'ryit_user_interests_study' //more info about your interests
      );
    
      $fields = array(array("Vision & Roadmap", $fields_goals), array("Purpose & Business", $fields_interests));
    
      $active_field = 'vision-roadmap';
      $echo .= '<div class="main" active-field="' . $active_field . '">';
      
      //Set up category tabs
      $echo .= '<ul class="tabs">';
      foreach($fields as $field) {
        $echo .= '<li id="tab-' . sanitize_title($field[0]) . '"';
        if($active_field == sanitize_title($field[0])) {
          $echo .= 'class="active"';
        }
        $echo .= '>' . $field[0] . '</li>';
      }
      $echo .= '<li id="tab-all">View all</li>';
      $echo .= '</ul>';
    
      $fields_with_val = 0;
      $fields_echo = "";
    
      //Set up fields inside categories
    
      foreach($fields as $field_group) {
        $echo .= '<div class="field-group" id="field-group-' . sanitize_title($field_group[0]) . '">';
        $fields = $field_group[1];
        $fields_echo = "";
    
        foreach ($fields as $field) {
    
          //get essential profile data
          $field_obj = get_field_object($field, 'user_' . $user_id);
          
          if(!empty($field_obj['value']) || ($user_id == $current_user_id)) {
            $fields_with_val++;
            $can_edit = ($user_id == $current_user_id) ? " can-edit" : "";
            $fields_echo .= '<div id="' . $field_obj['name'] . '" class="field' . $can_edit . '">';
            $fields_echo .= '<h3>' . $field_obj['label'] . '</h3>';
            $fields_echo .= '<div class="field-data">';
            if(empty($field_obj['value']) && ($user_id == $current_user_id)) {
              $field_echo = '<div class="field-content"><p class="instructions">Instructions: ' . $field_obj['instructions'] . '</p><p class="add-response button">Add your response</p></div>';
            }
            else {
              if(is_array($field_obj['value'])) {
                $i = 0;
                $val_output = ""; 
                foreach($field_obj['value'] as $val) {
                  if($i>0) {
                    $val_output .= ", ";
                  }
                  $val_output .= $val;
                  $i++;
                }
                $field_echo = '<div class="field-content">' . $val_output . '</div>';
              }
              else {
                $field_echo = '<div class="field-content">' . $field_obj['value'] . '</div>';
              }
            }
            $fields_echo .= $field_echo;
            //echo "user id: " . $user_id;
            //echo "current user id: " . $current_user_id;
    
            if($user_id == $current_user_id) {
              $settings = array(
                'post_id' => 'user_' . $user_id,
                'html_updated_message' => '',
                'fields' => array($field),
                'id' => 'form_' . $field_obj['name']
              );
              ob_start();
              acf_form($settings);
              $form = ob_get_clean();
              $fields_echo .= $form; 
            }
    
            $fields_echo .= '</div>'; //end field-data
            $fields_echo .= '</div>'; //end field
          }
        }

    Now, look at where I define the $fields_goals array.

    The first two array entries refer to fields ‘vision’ and ‘mission’ inside the group ‘ryit_user_legacy’ and the last three fields belong inside ‘ryit_user_goals’.

    When I define them with their alphanumeric names like this, the front end shows the values currently visible in the backend. But when I SAVE them, the values don’t change. Nothing gets saved.

    When I change to using the field KEYS however, I manage to save the values, but the values don’t show on the profile in the backend. In other words, the KEY sends the data SOMEWHERE, but it doesn’t show up on the profile.

    This seems like a bug to me, but I’m not sure.

    Everything works fine with fields which aren’t inside of groups. I’m stumped.

    Eivind