• Hi there

    I am adding a custom field in user profile fields.
    Checkbox group called “Skils”.
    The user can select one or more values from (Java, JavaScript, PHP, MySQL).

    How will I save these in wp usermeta? What will be the right code?

    foreach($_POST['skills'] as $value)
    {
       update_user_meta( $user_id, 'skills', $value ); 
    }

    Thanks.

    • This topic was modified 5 years, 4 months ago by mplusplus.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator t-p

    (@t-p)

    Thread Starter mplusplus

    (@mplusplus)

    @t-p that example is for a text-box, which I am able to do. My issue is with checkboxes.
    Any other thoughts are most welcome.

    Thanks

    Thread Starter mplusplus

    (@mplusplus)

    To add:

    I am using:

    <input type="checkbox" name="skills[]" id="1" value="php"/>PHP</input>
    <input type="checkbox" name="skills[]" id="2" value="mysql"/>MySQL</input>

    //this returns null despite my selecting values in checkboxes.
    echo $_POST['skills'];

    Thanks.

    Moderator bcworkz

    (@bcworkz)

    Selecting boxes when the tag name attribute includes “[]” means the selections come in as an array. You cannot echo arrays, you need to print_r() arrays.

    You could actually store the entire array as-is into post meta, but in fact you need to validate and sanitize all submitted values before saving into the DB. You could loop through the data to validate and sanitize, while collecting clean data into a new array. Then save the entire array as a single meta value.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Storing Checkbox group output in WP Usermeta?’ is closed to new replies.