bump! Anyone else tried to do this… it seems a reasonably fundamental thing to want to do with profile fields?
Yeah, I would agree that a functionality like that would be nice.
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.
@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.
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?
@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.
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!!!
@slashnata – no entiendo tu pregunta exactamente
@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
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.
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