0

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jawequo
  • 7
  • 1

1 Answers1

0

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 );
    }
 
}
Rochelle
  • 513
  • 1
  • 4
  • 8
  • unfortunately not working - using it leads to an empty meta field in the end. The already existing values were also deleted after form submission – Jawequo Mar 17 '22 at 20:00
  • Sorry, I edited it and now it should work fine (tested on my end) – Rochelle Mar 17 '22 at 23:31
  • Yes it does, thank you so much was going crazy with this. As i wanted a line break instead of comma i just replaced the "," with "\n" – Jawequo Mar 17 '22 at 23:54