pods-framework / pods-gravity-forms

Integration with Gravity Forms plugin for WordPress (https://pods.io/gravityforms/)
https://wordpress.org/plugins/pods-gravity-forms/
GNU General Public License v2.0
62 stars 10 forks source link

Pre-Populate GF with PODS Data #43

Closed kkramer2195 closed 7 years ago

kkramer2195 commented 8 years ago

I have modified the following code snippet from an iThemes Training class on pre-populating gravity forms:

// Prefill with User Data function populate_usermeta($meta_key){ global $current_user; return $current_user->__get($meta_key); } add_filter('gform_field_value_userfirstname', create_function("", '$value = populate_usermeta(\'user_firstname\'); return $value;' )); add_filter('gform_field_value_userlastname', create_function("", '$value = populate_usermeta(\'user_lastname\'); return $value;' )); add_filter('gform_field_value_useremail', create_function("", '$value = populate_usermeta(\'user_email\');return $value;' ));

The above code snippet pre-populates data from the current logged in user (user_firstname, user_lastname and user_email), however when I modify the necessary fields to pull data from POD of extended user, I get no values returned. The above snippet works perfect for First Name, Last name and email on a new form (created to just test code)

// Prefill with User Data function populate_usermeta($meta_key){ global $current_user; return $current_user->__get($meta_key); }
add_filter('gform_field_value_deptname', create_function(" ", '$value = populate_usermeta(\'departmentname\'); return $value;' )); add_filter('gform_field_value_deptid', create_function(" ", '$value = populate_usermeta(\'departmentid\'); return $value;' )); add_filter('gform_field_value_billing', create_function(" ", '$value = populate_usermeta(\'billingsite\');return $value;' ));

My POD is an extension of User and only contains the three fields above and my GF form is set to accept the values: deptname, deptid, billing).

Basically, I have custom fields that are added to user to show Department Name, Departing ID and Billing site, when the user logs in to submit an incident via GF, we want their department name and ID to be pre-populated to save the department from having to type that information on every incident.

Hope this information help, and feel free to inquire with any more details needed.

sc0ttkclark commented 8 years ago

I bet if the pod is a user pod, we could populate it with the 'current user' data, which shouldn't be difficult. Just need to get some JS to show/hide the optional mapping field if the pod selected is a user pod.

kkramer2195 commented 8 years ago

I was thinking it would be fairly easy since it is an extension of User, I checked the db and found the entries I am expecting to pull from DB to my GF screen....

kkramer2195 commented 8 years ago

Any update or ETA on this issue?

sc0ttkclark commented 7 years ago

I've added the ability to enable 'editing' form data using the current logged in user ID as part of work in #55

Should be out in 1.3 :)