Skip to:
Content
Pages
Categories
Search
Top
Bottom

Set checbox value with xprofile_set_field_data

  • @koendb

    Participant

    Hi, so I want to give new users the ability to register for a newsletter with a checkbox.
    When I change the checkbox to a text box field in both my form and buddypress everything works just fine.

    $newsletter is either ‘true’ or ‘false’.
    Line of code:
    $meta_update = xprofile_set_field_data( ‘7’, $user_id, $newsletter);

    In Buddypress profile fields I added
    Field Title: ‘Newsletter’
    Required?: Not required
    Field Type: checkboxes
    sort order: custom
    ‘Yes, I want to receive a newsletter’ and ‘default value’ not checked

    When registering a new user with a checked checkbox the checkbox on the new user profile page stays unchecked.

    Any thoughts?

    (WP 3.6, BP 1.8.1)

Viewing 5 replies - 1 through 5 (of 5 total)
  • @koendb

    Participant

    Anybody?

    @latinosamorir

    Participant

    Did you ever figure this out?

    I can’t seem to save checkbox info with xprofile_set_field_data

    I tried serialize($field_value) but nothing.

    Any other ideas?

    @koendb

    Participant

    Nope 🙁
    Any help is still appreciated.

    @danbp

    Participant

    Maybe read here, the post and all the comments:

    Fetching and Showing only Specific fields from BuddyPress XProfile data

    @koendb

    Participant

    Got it 🙂

    All you need is the value of the checkbox.
    <input id="nieuwsbrief" type="checkbox" value="newsletter"
    You can find/set this value in the users –> profile fields page

    Then just set the value of $newsletter to ‘newsletter’ when the box is checked or any other value if it’s not and use:
    $meta_update = xprofile_set_field_data( '<em>name or id of field</em>', $user_id, $newsletter);

    Glad to answer any questions

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Set checbox value with xprofile_set_field_data’ is closed to new replies.
Skip to toolbar