BuddyDev

Search

How do do data validation for profile fields?

  • Participant
    Level: Initiated
    Posts: 1
    Vincent on #43762

    I want to make sure users’ input for one of their profile fields match a regexp. Where should I start?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2933
    Ravi on #43767

    Hello Vincent,

    Welcome to the BuddyDev Forums.

    Please look at the filter with name “bp_xprofile_set_field_data_pre_validate”. You can use this filter to validate user input. Please let me know if you need any further assistance with this.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 1
    Vincent on #43784

    Hi Keymaster. thanks for your reply.
    It seems to me this filter is used to alter users’ input but not validate it.

    I have been trying to find in the code an example where buddyboss/buddypress validates user’s input(So I can maybe mimic it), but there seems to be none.

    To clarify, I want to show an error message when users input something invalid(in this case not matching the regexp). I think I must be able to do it with javascript, but if buddypress has something built-in, then I think it will be better to utilize it.

    I am still checking the hooks. For now bp_xprofile_field_type_is_valid looks promising. Any thoughts?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2933
    Ravi on #43801

    Hello Vincent,

    Thank you for the acknowledgement.

    The filter with name “bp_xprofile_set_field_data_pre_validate” allows to validate user inputs for the field where second filter “bp_xprofile_field_type_is_valid” allows to check the input against the field registered format. Yes, You can use the filter “bp_xprofile_field_type_is_valid” as well. As it runs later when setting the field value.

    Please let me know if you need any further assistance.

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: not resolved