Support

Account

Forum Replies Created

  • You’re welcome. And I have a deeper understanding of these issues myself after working through them.

    Another hint, take a close look at:

    the Gravity Forms “User Registration Add-On”.

    https://www.gravityforms.com/add-ons/user-registration/

    will appear is: Form -> Settings -> User Registration

    Jon

  • OK, I had thought of a couple ideas to try this morning, and things came together. Let me post my revised code. Essentially, I tried to follow the natural formatting to see if I could get everything to fall in line further along. I decided to convert the initial variable to an array, and that is what made everything else fall in line.

    // get mentor & new mentee user arrays from the Match Metadata fields
    $mentor = get_field(‘match_mentor’, $post_id);
    $mentee = get_field(‘match_mentee’, $post_id);

    //get ID from mentor array
    $match_mentor_id = $mentor[‘ID’];
    //get ID from mentee array
    $match_mentee_id = $mentee[‘ID’];

    //set up the mentor user_post_id
    $mentor_post_id = “user_”.$match_mentor_id;

    //get user array from mentor curent_users
    $current_mentees = get_field(‘current_mentees’, $mentor_post_id, false);

    // see if the current mentees is null or has a mentee already
    if ($current_mentees == ”){

    //put data in proper format
    $current_mentees = array();

    }

    //combine old mentee(s) with new mentee
    array_push( $current_mentees , $match_mentee_id);

    //write new current mentees back to the Mentor User Meta fields
    update_field(‘current_mentees’ , $current_mentees , $mentor_post_id);

  • Hi Michael,
    Yes, I’ve been struggling with this for a while. I have 2 situations, posting to a null field and to one that already has a user ID or array.
    I can more or less do them separately, but not both. Hoping for some help today.
    Otherwise, I’ll work on it to try and find some way past this barrier.
    And I’ll let you know if I find a solution.
    Jon

  • Some additional information:

    The match_mentor & match_mentee and current_mentees are all ACF fields.
    I am able to manually add (mentee) users (single & multiple) to the current_mentees through the dropdown in the user account. It appears as an array of arrays.
    The first one looks like: a:1:{i:0;s:2:”60″;}
    Adding the second one gives me: a:2:{i:0;s:2:”60″;i:1;s:2:”57″;}
    This is functional for my purpose. I’d like the code to do the same.

    Using the above code to add one user, in the current_mentees field/DB I see 60.
    And then adding the 2nd one, I get a:1:{i:0;i:57;}. (It replaces the first one).

  • John,

    That was what I needed, I really appreciate it!

    Jon

  • Hi John,
    Thanks for the advice! I’ll try this out then get back with you later this morning.
    Jon

  • Update:
    I was able to write the string: ‘a:1:{i:0;s:2:”57″;}’ back to the database.
    And then tried: ‘a:2:{i:0;s:2:”55″;i:1;s:2:”57″;}’ and also ‘a:3:{i:0;s:2:”55″;i:1;s:2:”57″;i:2;s:2:”60″;}’, they worked too.
    so maybe that is the way I need to fix this.
    Any suggestions for the most efficient way to code this?

    To recap:

    I pull the string from the database, may be 0 characters, on up… in that string array.
    I’ll need to add a new one to the end that and then put it back into the database.

    So:

    $old_current_mentees = ‘a:1:{i:0;s:2:”55″;}’ or ‘a:2:{i:0;s:2:”55″;i:1;s:2:”57″;}’ or ‘a:3:{i:0;s:2:”55″;i:1;s:2:”57″;i:2;s:2:”62″;}’; etc
    add new_mentee = a:2:{i:0;s:2:”55″;i:1;s:2:”68″; to the string array
    make sure it has the proper wrappers

    $new_current_mentees = $old_current_mentees + new_mentee

    write it to a variable to upload back into the DB.

    Any suggestions for the most efficient way to code this? Functions to use? Sample code?

    Thanks!

Viewing 7 posts - 1 through 7 (of 7 total)