Support

Account

Home Forums ACF PRO Save ACF values to user profile

Solved

Save ACF values to user profile

  • Hi,

    I’ve created a front-end questionnaire using nested repeater fields (question item with a test field for the question and test fields nested repeater for the available answers), inside a custom page template.

    Now I got a request to save each question and its answer to the user profile, in order to be able to check later what answers he gave.

    Do I need to rebuild this repeater in the user profile or is there a way to save it from the current location?

  • You need to get the current user’s ID and then specify the “post ID” to save the values to when calling acf_form(). The post ID will be "user_{$user_id}" See the post_id option for acf_form() https://www.advancedcustomfields.com/resources/acf_form/

  • I dodn’t even think it could be that simple.
    thanks!

    made a new group of radio button fields and submitted with

     <?php
                                $options = array(
                                    'post_id' => 'user_'.$current_user->ID,
                                    'field_groups' => array(232),
                                    'form' => true,
                                    'return' => add_query_arg( 'updated', 'true', get_permalink() ),
                                    'html_before_fields' => '',
                                    'html_after_fields' => '',
                                    'submit_value' => 'Update'
                                );
    
                                acf_form( $options );
                                ?>

    now my only problem is that I need to make some of the radio buttons to have the same value inside the same group.
    is it possible?

  • I’m not sure I understand your follow up question. Can you explain further?

  • the answers in this form, are based on radio buttons i.e.
    yes : YES
    no : NO
    hellno : Hell No

    only I use numbers for the values.
    for some reason, I can’t have two buttons with the same value.
    i.e.
    2 : YES
    1 : No
    1 : Hell No

    The reason I need it is to sum all the values in order to see if the user is qualified. in some questions, I have two answers that have the same score (I don’t care for example if he says “no” or “hell no”, but I do need to give him the chance to say it.

    hope I made it clearer 🙂

  • There isn’t any way to do this with ACF because of the way that ACF stores the values and labels for the radio buttons. You would need to have a different value for every choice.

    You could have choices like

    
    1 : No
    1.0 : Hell No
    1.00 : Are you nuts?
    

    These values would be stored as strings and you could convert them to integers when getting the values

    
    $value = intval(get_field('radio_field'));
    
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.