Add user meta with gravity forms

1.1k Views Asked by At

I'm kinda stuck right now and would appreciate some help!

I want to save the input from a gravity form into the users profile meta but it's a form users do more often so I need the value to be saved in a list every time it gets submitted. In the meta profile I'm using a custom textarea field to store the values.

Right now I'm using this code and it stores it one time but always overrides the recent value with the new value:

add_action("gform_after_submission_9", "gravity_post_submission", 10, 2);
function gravity_post_submission ($entry, $form){
    
    //Gets field id 10
    $values = rgar( $entry, '19' );
    
    update_user_meta( get_current_user_id(), 'keywords', $values );
}

But I need the value to be saved every time in a new row of the meta textarea field and not be overwritten.

You guys have an idea how I could achieve this?

1

There are 1 best solutions below

3
On BEST ANSWER

Would this work?

add_action("gform_after_submission_9", "gravity_post_submission", 10, 2);
function gravity_post_submission($entry, $form){
    $value =$entry['19'];
    $meta_value = get_user_meta(get_current_user_id(), 'keywords', true);
    if (!empty($meta_value )){
        $meta_array = explode(",",$meta_value);
        array_push($meta_array, $value );
        update_user_meta( get_current_user_id(), 'keywords', implode(",",$meta_array ));
    }else{
        update_user_meta( get_current_user_id(), 'keywords', $value );
    }
 
}