Tips and Tricks HQ Support Portal › Forums › WP eMember › eMember – prepopulate Gravity form fields with member details
Tagged: eMember, Gravity Forms, populate gravity form field
- This topic has 9 replies, 4 voices, and was last updated 10 years, 6 months ago by wzp.
-
AuthorPosts
-
November 27, 2012 at 7:26 pm #8015igillandersMember
Hello,
I have been searching for several days now to figure out how I can get certain fields in my Gravity forms to be prepopulated with eMember member registration data. Basically, I need to have a few fields (name, email address, etc.) prepopulated from the member currently logged into eMember.
I have already contacted Gravity Forms who provided me with some insights. Not being a programmer and not knowing PHP, I am struggling. I know that some PHP code needs to be inserted in the template’s functions.php file, but not exactly clear what.
The guy at Gravity pointed me to a link explaining how their plugin handles dynamic population with hooks. http://www.gravityhelp.com/documentation/page/Using_Dynamic_Population#Hooks
I am really hoping (maybe dreaming!) that someone nice out there could give me some step-by-step instructions to make this happen. I am very familiar with both plugins, just need help with the coding. If this is too much to ask, I would be willing to pay a developer to do what I am sure is quite straight-forward.
November 28, 2012 at 5:14 am #51826adminKeymasterLets do a test with the email field first to see how we go. Please tell me the “parameter” name for the email field in your Gravity Form. I am referring to the following:
It will allow me to give you a sample code to test.
November 28, 2012 at 4:01 pm #51827igillandersMemberHi,
Not sure what the parameter name should be. I imagine it could be anything, no? Is is not just a variable? If so, I guess I would call it “agent_email”.
November 29, 2012 at 3:36 am #51828adminKeymasterYes, I think that parameter name can be anything. So lets assume you are going to call that parameter “agent_email”. The code you need to add in your “functions.php” will be the following:
add_filter('gform_field_value_agent_email', 'custom_population_function_for_agent_email');
function custom_population_function_for_agent_email($value){
if(wp_emember_is_member_logged_in()){
$emember_auth = Emember_Auth::getInstance();
$email = $emember_auth->getUserInfo('email');
return $email;
}
}Let me know if that populates the email field with the members email.
November 30, 2012 at 12:30 am #51829igillandersMemberIt worked beautifully! Now, if I want to populate multiple fields can you please give me the code? Would I simply replicate the entire above code once for each field?
Here are the eMember fields and their corresponding parameter names:
email
> agent_emailcompany—-> agent_company
country—-> agent_country
Thanks very much!!
November 30, 2012 at 4:56 am #51830adminKeymasterYes, you should simply replicate the above code for each field. Here is an example code:
add_filter('gform_field_value_agent_country', 'custom_populate_agent_country');
function custom_populate_agent_country($value){
if(wp_emember_is_member_logged_in()){
$emember_auth = Emember_Auth::getInstance();
$country= $emember_auth->getUserInfo('country');
return $country;
}
}
add_filter('gform_field_value_agent_company', 'custom_populate_agent_company');
function custom_populate_agent_company($value){
if(wp_emember_is_member_logged_in()){
$emember_auth = Emember_Auth::getInstance();
$company_name= $emember_auth->getUserInfo('company_name');
return $company_name;
}
}May 3, 2014 at 10:20 pm #51831McpMemberHi,
I know that’s an old post but i didn’t want create a new one for my answer.
First, thank you for this code this is just what i need.
But can you give me the full list of variable name for the default eMember field like : name, phone, …
It would help me a lot for prepopulate field in my GF forms.
Thank you a lot.
May 3, 2014 at 10:25 pm #51832wzpModeratorIs this what you really want?
May 3, 2014 at 10:42 pm #51833McpMemberThis is exactly what i really want.
Big Thanks to you!
May 3, 2014 at 10:44 pm #51834wzpModerator -
AuthorPosts
- You must be logged in to reply to this topic.