You rock!! Thank you!
Unfortunately I had to hack a bit of the core code to get everything working just the way I needed it to, but good news is, I think I now have a way to link my saved form to a logged-in user's profile (so the user can come back and edit the form / resubmit later). In any case this is working for me. :-)
Here's what I had to do to achieve it:
UPDATE - see this post for a revised solution:
http://www.gravityhelp.com/forums/topic/saving-a-form#post-32318
- In your form, go into each field's Advanced tab and click "Allow Field to be Populated Dynamically. Enter a parameter name - it can be anything, but should be unique.
- Change line 909 of forms_model.php to read:
return apply_filters("gform_field_value_$name", apply_filters("gform_field_value", $value, $name));
- Add the following to your theme's functions.php file:
// RETRIEVE PARAMETER_NAME FOR FIELDS AND ADD TO WP_USERMETA
add_action('gform_post_submission', 'save_entry_values', 10, 2);
function save_entry_values($entry, $form){
$userid = $entry['created_by']; // retrieve user ID
$submitted_info = array();
foreach($form['fields'] as $field) {
$value = RGFormsModel::get_lead_field_value($entry, $field);
if($value) {
$submitted_info[] = array($field['inputName'] => $value); // retrieves parameter_names values
update_user_meta($userid, $field['inputName'], $value); // stores parameter_name values in wp_usermeta table
}
}
}
// RUN REVISED GFORM_FIELD_VALUE_YOUR_PARAMETER FILTER
add_filter('gform_field_value', 'populate_user_meta', 10, 2);
function populate_user_meta($value, $name){
global $user_ID;
$field_user_meta = get_the_author_meta($name, $user_ID);
return $field_user_meta;
}
- Now when logged-in users fill out a form, they should be able to return to that same form later and have all their previous answers pre-populated.
The way the filter is rewritten should allow users to use both the gform_field_value filter and the original gform_field_value_your_parameter filter - the latter will overwrite the former.
Let me know if you can think of a better way to do this - any of it - and/or if there's a way I can move that rewritten filter into my local functions.php file. I hate to edit the core code, just couldn't see a way around it in this instance.
Thanks again for your help!
Michelle
Posted 13 years ago on Wednesday August 10, 2011 |
Permalink