UsersWP Default Value for Gravity Forms
This topic contains 11 replies, has 3 voices, and was last updated by Stiofan O’Connor 6 years, 11 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support TicketTagged: autofill, default values, gravity forms
-
AuthorPosts
-
November 21, 2017 at 9:22 am #1021
Hello,
I’m trying to setup default values for gravity form input fields using the registered user data.
To pull the default wordpress user value in gravity forms I would use {user:first_name}, but how to I pull the UsersWP user values?
November 21, 2017 at 11:19 am #1026Hello,
The first/last name should be exactly the same, we use the WP values for that.
Other non standard values i don’t think can be added yet, if Gravity forms has a filter for that we might be able to add our parameters. I’ll try and contact them to see if they can provide us a developer licence to add integrations.Thanks,
Stiofan
November 22, 2017 at 8:43 am #1040Hey Stiofan,
Thanks for the reply. I did some more digging on my end and I also reached out to Gravity Forms to see what they would recommend and this is what they told me:
If you need to pull from another database table, you won’t be able to use the Gravity Forms usermeta merge tags. You can use this filter to pull data from anywhere to populate fields in your form (it’s not specific to UserWP):
https://docs.gravityforms.com/gform_field_value_parameter_name/
So went ahead and tried to set that up, but I don’t know how to call the UserWP database tables for the uwp_usermeta.
This is what I’ve tried so far: got conformation from Gravity forms that you can not use merge tags or the default values unless its for wordpress or gravity forms user data, but you can use parameters. So using the help article Gravity forms sent me I setup my parameters for my data (see screen shot) and added the following filter which returns a value from the database. This isn’t working and I’m not sure how I would go about pulling the upw_usermeta data from the database of current logged in user.
// define the fields we'll be populating $fields = array('uwp_account_company', 'uwp_account_phone'); // loop through fields and add the Gravity Forms filters foreach($fields as $field) add_filter('gform_field_value_'.$field, 'my_populate_field'); // the callback that gets called to populate each field function my_populate_field($value){ // we have to wrestle the field name out of the filter name, // since GF doesn't pass it to us $filter = current_filter(); if(!$filter) return ''; $field = str_replace('gform_field_value_', '', $filter); if(!$field) return ''; // get the current logged in user object $user = wp_get_current_user(); // We'll just return the user_meta value for the key we're given. // In most cases, we'd want to do some checks and/or apply some special // case logic before returning. return get_user_meta($user->ID, $field, true); }
What are your thoughts?
November 22, 2017 at 10:07 am #1044if you can give me wp-admin details in a private reply(only staff can see) i’ll run some tests on your site and if i get it working i’ll likely add it to core’s next release.
Thanks,
Stiofan
December 1, 2017 at 9:18 am #1089This reply has been marked as private.December 1, 2017 at 2:31 pm #1090This reply has been marked as private.December 1, 2017 at 7:03 pm #1091This reply has been marked as private.December 4, 2017 at 10:29 am #1102Can you please check your FTP details, non of the team can connect with the above details.
Thanks,
Stiofan
December 4, 2017 at 7:15 pm #1105This reply has been marked as private.December 4, 2017 at 7:44 pm #1108Hello,
I can confirm the credentials worked for me.
December 4, 2017 at 7:45 pm #1109cool thanks guys!
December 5, 2017 at 2:31 pm #1120I have added the following snippet but not tested it, please test it and let us know.
For example if you have a custom field with html_var of “gender” then you would add a GF field of “uwp_account_gender” and that should work.Please let us know how u get on.
Stiofan
add_filter( 'gform_field_value', '_gf_populate_uwp_fields', 10, 3 ); function _gf_populate_uwp_fields( $value, $field, $name ) { $user_id = get_current_user_id(); if(!$user_id){return $value;} $values = array(); $usermeta = uwp_get_usermeta_row($user_id); if(!empty($usermeta)){ foreach($usermeta as $key=>$meta){ if (strpos($key, 'uwp_account_') === 0) { $values[$key] = $meta; } } } return isset( $values[ $name ] ) ? $values[ $name ] : $value; }
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket