PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Can I Pre-Populate Or Call From Buddypress Profile Data?

  1. perspective
    Member

    I have just bought Gravity Forms and read all the forum posts about pre-populating but am either still stuck or am mis-understanding the abilities of Gravity Forms so I hope someone can help with this?

    I have set up a test form at http://www.timesharestaff.com/test-form/
    I want to be able to pull from Buddypress Profile Data for the logged in user to populate the fields such as Address, Country etc so that my users can have an auto-fill job application form based on the info they provided upon registration which mimics most of the test form I have provided.

    Is this possible and can you please help - much appreciated.

    Posted 13 years ago on Wednesday December 29, 2010 | Permalink
  2. Yes, it's possible but you have to write custom code and use available Gravity Forms API hooks to pre-populate these fields. Here is a form post that discusses how to pre-populate fields with user data:

    http://forum.gravityhelp.com/topic/pre-populate-form-with-user-data

    Please note this example is pre-populating user meta. BuddyPress profile data is stored in it's own database table, not in user meta. You would have to customize this code to get the BuddyPress profile data.

    You would repeat these steps for each field you want to pre-populate.

    Posted 13 years ago on Wednesday December 29, 2010 | Permalink
  3. perspective
    Member

    Thanks for your response - I had already seen that post and implemented the code that was given as an example

    <?php
    add_filter("gform_field_value_email", "populate_email");
    function populate_email($value){
    return "john@doe.com";
    }
    ?>

    And I can get the "john@doe.com" to appear where it's supposed to but cannot get any form of Buddypress action / data call to work - whatever else I put inside of the " " marks just shows as text.

    All I need is one working example of a buddypress data call as part of the above code example that works and I can work out everything else from there. This is a fabulous plugin and this final stage makes it an invaluable addition to our website, so any additional help is much appreciated and will enable us to make best use of the multisite license we have just bought.

    Posted 13 years ago on Wednesday December 29, 2010 | Permalink
  4. What version of BuddyPress are you using?

    Posted 13 years ago on Wednesday December 29, 2010 | Permalink
  5. perspective
    Member

    Buddypress 1.2.6 and Wordpress 3.03 - thank you in advance.

    Posted 13 years ago on Thursday December 30, 2010 | Permalink
  6. Here is a quick and dirty function you can add to your functions.php that will let you get any user meta data from the BP user data table.

    http://pastie.org/1416206

    Assuming you know the user ID and field ID, you can use this to prepopulate field values like so:

    <?php
    
    add_filter("gform_field_value_email", "populate_email");
    function populate_email($value){
         global $current_user;
         get_currentuserinfo();
    
         return get_bp_user_data($current_user->ID, 3);
    }
    
    ?>

    The $current_user->ID being the current user's ID and the 3 being the field ID of the BuddyPress field you wish to get the value of. To get this field ID take a peek at the source code on the BP Profile Field Setup page and you'll see something like this: http://grab.by/87B1 -- the number following the "field_" is the ID of the field.

    Hope this helps!

    Posted 13 years ago on Thursday December 30, 2010 | Permalink
  7. perspective
    Member

    Hi David,

    Unfortunately this still doesn't work, nor does what seems like a hundred variations I've tried before coming back to you. Any other ideas or guidance on how to implement?

    Posted 13 years ago on Tuesday January 4, 2011 | Permalink
  8. perspective
    Member

    I've found the problem - below is the correct code to make it work...

    <?php
    add_filter("gform_field_value_address", "populate_address");
    function populate_address($value){
         global $current_user;
         get_currentuserinfo();
         return xprofile_get_field_data('address', $current_user->ID);
    }
    ?>

    I hope this code helps other Gravity Forms users.

    BUT, I cannot get it to work on drop down menu fields - any ideas?

    Posted 13 years ago on Wednesday January 5, 2011 | Permalink
  9. Unfortunately, drop down fields can not be populated with this hook. You can, however, use the gform_pre_render hook to do this. Try this:

    http://pastie.org/1432081

    Very similar to what you're doing for single input population, but here we're creating an array is required to populate drop down fields.

    The example output of the code above is something like this: http://grab.by/8dtR -- I'm not sure exactly what other options you want for your drop down so I put three of the same just so you could see what multiple options would look like. Hope this helps.

    Posted 13 years ago on Wednesday January 5, 2011 | Permalink
  10. enclave
    Member

    Very handy. Will be giving this a whirl

    Posted 13 years ago on Thursday January 6, 2011 | Permalink
  11. oulab
    Member

    Hi,

    I'm trying pre-populate a form field with Gravity form. I'm using BuddyPress Default 1.2.7.

    Currently each user profile has a form. I would like to add the username of the profile to the form dynamically. This is my attempt so far from using the forum and documentation as guidance

    http://www.pastie.org/2068805

    No luck yet.

    These are the buddypress variables

    http://codex.buddypress.org/developer-docs/the-bp-global/

    Help would be much appreciated.

    Thanks.

    Also is there a particular section i need to paste in the code in the functions.php file?

    Posted 12 years ago on Tuesday June 14, 2011 | Permalink
  12. I am succesfully pre populating wordpress user meta, but I have searched all the forum and I didn't find an answer how to prepopulate buddypress profile data assuming that I don't know user id, I simply want the logged in user to have pre populate first_name and last_name from wordpress and some other fields from buddypress profile groups, is it difficult? I hope that buddypress profile fields works very similarly to user_meta, I tried many combinations from this website and nothing works for me - (the name of the field in buddypress profile is Phone - group_id=5&field_id=59 - this is the slug from edit profile page :
    This is the example which doesn't work in functions.php

    add_filter("form_field_value_phone", "populate_phone");
    function populate_phone() {
    	$current_user = wp_get_current_user();
    	$current_user_id = $current_user->ID;
    	$phone = bp_profile_field_data( array('user_id'=>$current_user_id,'field'=>'Phone' ));
    	return $phone;
    }
    ?>

    Can you help me to get it work ?

    Posted 10 years ago on Sunday July 7, 2013 | Permalink
  13. Richard Vav
    Administrator

    If you still require assistance with this please open a new support ticket or a priority support ticket if you are a developer license holder. Thank you.

    Posted 10 years ago on Thursday July 25, 2013 | Permalink

This topic has been resolved and has been closed to new replies.