Skip to:
Content
Pages
Categories
Search
Top
Bottom

dynamically create new sets of profile fields


  • Roger Coathup
    Participant

    @rogercoathup

    We want to be able to dynamically create new profile fields:

    e.g. we have a set of profile fields for employment: employer name, dates employed, etc.

    When the user enters one set of employment fields, we want to create another set, so they can enter a second employer, and a third employer and so on.

    Creating as many set of fields as the user needs for all his employers. (this is pretty much the way Facebook or LinkedIn works)

    It looks to me like we need either arrays of profile groups, or a way to dynamically create fields.

    Any thoughts on how to do this in BuddyPress?

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

  • Roger Coathup
    Participant

    @rogercoathup

    bump! Anyone else tried to do this… it seems a reasonably fundamental thing to want to do with profile fields?


    paulhastings0
    Participant

    @paulhastings0

    Yeah, I would agree that a functionality like that would be nice.


    Boone Gorges
    Keymaster

    @boonebgorges

    This could be done, but it would take some custom coding. Here’s how I would structure it.

    1) Write some JS for the Edit Profile page that inserts a new set of fields based on user input (say, a button that says “Add another employer”). This wouldn’t really require any BP code in and of itself.

    2) Hook a function to ‘xprofile_updated_profile’, which is a do_action hook called right after all of the xprofile fields are saved. Grab the $_POST data, and see if there are any items in that array for which no profile fields yet exist. Use xprofile_insert_field() to create the new fields (it might be like employer_2_employer_address – something that iterates nicely).

    3) On the front end, you’ll want to make sure that not all of the employer groups are shown to each user on the edit profile screen. By default, each user sees each profile field. That means that if one person on your system listed ten employers, then everyone would see ten employer field groups when they went to edit their profile. You could do this in the profile edit template, by checking bp_get_the_profile_field_name() against a list of permitted field names.


    Roger Coathup
    Participant

    @rogercoathup

    @boonebgorges – Great that you think it can be done with the existing tables (I was considering adding some additional tables keyed on the user profile id). The hook into xprofile at the right place is what I was looking for.

    We are going to filter out profile fields where the user hasn’t input a value anyway (and not display them). I take it this is as simple as checking whether the field value is an empty string. Although, as you point out, you would still want these displayed on the edit page.

    So, it’s check for NULL and check for standard field (vs. extended field) name as well.


    Arx Poetica
    Participant

    @arxpoetica

    Just following up on this — what might some code look like? Say, to just even simply create a new profile field type and populate it once?


    Roger Coathup
    Participant

    @rogercoathup

    @arxpoetica – we haven’t implemented any code yet, as we may now be moving all profile field handling out of BuddyPress on this client project.

    If we do end up cutting BP code this, I’ll remember to post a snippet.


    Natasha
    Participant

    @slashnata

    Hello Roger, at the company where I work are asking me to do a development similar to your questions …. and you develop something?, suddenly you develop a plugin?

    Thank you very much!!!


    Roger Coathup
    Participant

    @rogercoathup

    @slashnata – no entiendo tu pregunta exactamente


    Roger Coathup
    Participant

    @rogercoathup

    @arxpoetica

    I don’t know if you found any code in the meantime, but in case you haven’t:

    The basic function to insert a new profile field is: xprofile_insert_field()

    And, to populate a field use: xprofile_set_field_data()

    They are defined in bp-xprofile.php


    Natasha
    Participant

    @slashnata

    Thank you very much for responding so fast!

    The company wants to develop with different profiles, for example for people in human resources, technology, etc. for different areas of the company.
    I’m looking at the function you gave me. My question was if suddenly you had already somewhat developed because i have little experience in PHP. :)

    Thank you very much.


    nanchante
    Participant

    @nanchante

    Did this ever get off the ground?

    I´m looking for the same kind of thing as Natasha but just different environment (university).
    Has anybody gone further on a real case (solution) and any piece of code that might be picked up as a starter.
    Thanks a lot.

    Andrés

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘dynamically create new sets of profile fields’ is closed to new replies.
Skip to toolbar