In my recent interview, I mentioned I was a fan of the Gravity Forms plugin.
I am. No qualms about that. 🙂
But surely, the Gravity Forms plugin has certain features, it could improve.
Case in point-> ‘Save and Continue’.
[space]
Whether you call it the ‘Save and Continue’ functionality, ‘Save Progress’ or ‘Save and Resume’, you know that for tedious multi-page forms, this functionality is a must. But for a while, the Gravity Forms plugin did not have a save progress feature.
Since version 1.9, Gravity Forms brought about a long awaited update, and added a ‘Save and continue’ functionality.
Here’s what the ‘Save and Continue’ feature does:
- It provides a setting at every form level, using which you can enable a ‘Save and Continue’ option
- If this option is enabled, a ‘Save and Continue’ link is shown next to the submit button
- If a user clicks this link, he/she is emailed another link. This link provides a user access to previously saved data
Now, this default functionality seems to do the job in certain scenarios, but it has a few limitations. For example, the user has to keep track of the save link, to restore his/her data. And what’s more is, every time the user clicks the save progress link, the entry is not updated, but instead, a new entry is saved.
I’ve noticed quite a few people ask whether they could update the data instead of creating a new entry each time.
That’s an interesting point (and a limitation I needed to solve).
You see, the default functionality provided by the Gravity Forms plugin, adds a new entry each time the save link is clicked. Instead, Gravity Forms users are looking to maintain just one entry per form filler, and update it each time the save option is clicked. So, there isn’t a need to provide a ‘save progress’ link.
What we would need to do, is check if the person filling the form, had previously saved the form, and then load the saved data.
[space]
Updating User Progress in Gravity Forms using the Data Persistence Add On
While attempting to find a solution for this particular scenario, I stumbled upon an extension plugin for Gravity Forms- the Gravity Forms Data Persistence add-on. Although upon further review, I found the updated version of the plugin- the Gravity Forms Data Persistence add-on Reloaded.
This plugin seemed promising. Based on the description, it seemed to solve my problem at hand. But unfortunately, it just didn’t work right.
The plugin seemed to be a very simple (but a powerful) plugin with few lined of code. I tried debugging the issue, and found the below piece of code:
add_action("gform_post_submission", "set_post_content", 10, 2);
The obvious problem was that the plugin was using a deprecated hook- gform_post_submission. This particular hook seemed to be the reason the plugin was not working.
So, I used an alternative hook Gravity Forms recommeded- gform_after_submission
And it worked!!! 😀
But hold on! There was a lot more to do!
Now, the plugin’s functionality was limited to logged in users i.e., only logged in users could keep on updating the form data. But what about users that weren’t logged in.
Well, I have a solution for that too!
Consider the below scenario:
Let’s suppose, you want to maintain persistent data for different users on your site, using the user’s identity (deduced using the username, email or ID) instead of his/her login data.
We can achieve this by tweaking the Gravity Forms Data Persistence add-on Reloaded.
Here’s how!
The plugin identifies the user in the functions ri_getFormOptionKeyForGF, and ri_getEntryOptionKeyForGF. So, I added a hook wdm_gf_pers_user_form to update the user data.
function ri_getFormOptionKeyForGF($form) { global $current_user; get_currentuserinfo(); // custom hook added to identify the user’s id $current_user = apply_filters( 'wdm_gf_pers_user_form' , $current_user); $option_key = $current_user->user_login . '_GF_' . $form['id']; return $option_key; }
Similarly I updated the ri_getEntryOptionKeyForGF function.
Now, I suggest once you’ve made these changes, you can add the hooks in a separate plugin or your theme. This will save you from the hassle of maintaining additional code in the original plugin, when you update it.
Next, the hook has to be defined as follows:
add_filter('wdm_gf_pers_user_form', array(&$this, 'set_gf_persistent_user'), 99, 1); // let's consider, we get the user ID from a query string variable 'userid' e.g. http://example.com/sample-data/?form=sample&userid=10 public function set_gf_persistent_user( $user ){ if(isset($_GET['userid']) && !empty($_GET['userid'])){ $user_id = $_GET['userid']; $user = get_userdata( $user_id ); } return $user; }
This code will hook into the default functionality provided by the plugin to work for any user instead of just logged in user.
Once you’re done with this, you’ll have a much simpler way to maintain a user’s data, even for users who aren’t logged in.
[space]
The advantage of adopting this approach is that you can maintain persistent data for logged in as well as guest users. And, you don’t even need a separate link to save user progress. The ‘submit’ button can be used to save the progress as well as submit the form.
Got any questions? Feel free to add them as comments, in the comment section below.
4 Responses
I’ ve been trying to get this plugin to work with Gravity Forms for a long multipage form. One must be logged in for to use it. But, I have tried to find the line you mention that was using the wrong hook and fix it. However, it still does not work.
I’m using the Add-on v 3.2.3 and Gravity 9.1.16
I find this line, which seems to be about clearing rather than storing:
// Updating or clearning persistence data on form submission
add_action(“gform_post_submission”, “ri_set_post_content”, 10, 2);
I don’t find any line that is same as the one you mentioned above.
This article is now defunct. Update to v 3.2.3 which now has the required functionality.
I mean version 3.3.1+.
I’ve got a similar scenario that I’m try to solve.
I’m using GF Save and Continue. I want to provide users with partial entries prior to registration by importing entries via Gravity View (Import Entries). Trouble is, I don’t have an option to set each entry with a save and continue URL generator – instead each entry is “submitted”. My purpose is to provide prefillled form for information I already have about our members. How can I change the status to a partial entry and generate a save and continue URL?