Updating user meta adds string count to value?


I am using Gravity Forms to update user meta. The user meta has to be serialized for another plugin, so I have to catch the value and convert it using the gform_pre_submission action before it gets uploaded to the database. It is converting just fine (a:1:{i:0;s:2:"62";}), and the entries on Gravity Forms show up exactly as I want. The problem is, when I look at the usermeta values in my phpMyAdmin, they are being stored with the string length first (ie. s:19:"a:1:{i:0;s:2:"62";}";), and I’m trying to get rid of that.

The problem seems to be in the conversion somewhere, as the string length doesn’t show up if I don’t convert it. Here is my code:

add_action( 'gform_pre_submission_13', 'serialize_user_tags' );
function serialize_user_tags( $form ) {
    $org_type_choice = rgpost( 'input_6' );
    $job_type_choice = rgpost( 'input_5' );
    $interest_choices = rgpost( 'input_7' );

    $string_org = 'a:1:{i:0;s:2:"'.$org_type_choice.'";}';
    $string_job = 'a:1:{i:0;s:2:"'.$job_type_choice.'";}';
    if (!is_array($interest_choices)){
        $string_int = 'a:1:{i:0;s:2:"'.$interest_choices.'";}';
    } else {
        $count_int = count($interest_choices);
        $string_int = 'a:'.$count_int.':{';
        $i_counter_int = 0;
        foreach ($interest_choices as $interest_choice) {
            $string_int .= 'i:'.$i_counter_int.';s:2:"'.$interest_choice.'";';
        $string_int .= '}';
    $_POST['input_6'] = $string_org;
    $_POST['input_5'] = $string_job;
    $_POST['input_7'] = $string_int;
Mr Gandy 4 months 0 Answers 10 views 0

Leave an answer