Sterc / FormIt

A dynamic form processing Snippet for MODX Revolution
https://docs.modx.com/current/en/extras/formit
33 stars 58 forks source link

Update existing saved form #94

Closed sepiariver closed 8 years ago

sepiariver commented 8 years ago

What It Does

Allows updating of saved forms or loading saved form data, if a valid hash key for a form record is provided.

GitPackageManagement config file and resolver is included to provide an alternate dev workflow.

A fix was added to the getlist processor, in case GPM is used to build the package, $ff['values'] is already an array, and not a string (due to json phptype in the schema). The check only runs fromJSON() if the value is a string, because the method expects a string anyways.

Why It's Needed

For lead generation activities, sometimes you want to capture form submission data from the very first step, perhaps via AJAX. The User might abandon the form, and normally with FormIt's &store option, the session data would be lost after the cache expires time, or the session is closed.

With the new param &updateSavedForm, as long as a valid hash key is provided, the User can update a previously saved form. If the user has lost their session, but the hash key is kept in localstorage (that's an example only, and purely up to the implementation) then the User can access the saved form values again, and continue where they left off.

Another example is if a User abandons the form after filling in their email address. You can run a (custom, not included) script to email the user a link to continue their form submission, with the hash key in the link params. If you call the included prehook, it will query saved forms based on the the $_GET param, and preload their previously submitted form values for them.

You also might have a Zapier integration with FormIt saved forms, that will let you do whatever you want with the submitted data—it will be easier to access it with the hash key. For example a link might be sent to marketing, to a protected Resource, that uses the prehook to populate the page with the submitted form data, so the marketing pro doesn't have to export from FormSave or view in the mgr. You could send a link with the FormItForm ID, but that exposes an easy way fetch any FormItForm you want just by incrementing the ID param. Rather if you use the prehook, it acts as a gateway: you must have the unique hash key to access the record.

Example Usage

[[!FormIt? 
    &hooks=`FormItSaveForm` 
    &store=`1` 
    &storeTime=`604800`
    &updateSavedForm=`values`
]]
[[!FormItRetriever]]
<form method="POST">
    <input type="text" name="savedFormHashKey" value="[[!+fi.savedFormHashKey]]">
    <label for="test">Value: </label><input type="text" name="test" value="[[!+fi.test]]">
    <input type="submit" value="Submit">
</form>

The above example uses the old-fashioned FormIt &store option to load in the hash key for the user, in case they go away and come back to the same browser session.

[[!FormIt? 
    &preHooks=`FormItLoadSavedForm` 
    &hooks=`FormItSaveForm` 
    &updateSavedForm=`values`
]]
<form method="POST">
    <input type="text" name="savedFormHashKey" value="[[!+fi.savedFormHashKey]]">
    <label for="test">Value: </label><input type="text" name="test" value="[[!+fi.test]]">
    <input type="submit" value="Submit">
</form>

This one pre-fills the form fields with previously saved values if the hash key is provided via $_GET

joeke commented 8 years ago

Hi @sepiariver Thanks for your contribution YJ, much appreciated! I'll look into it today and if everything checks out OK, I will merge it. Together with some other PR's and issue fixes hopefully we'll push a new FormIt release this week!

Carrrven commented 6 years ago

Hello. Is there any solution that I could send using the FormItAutoResponder link with the hash?

janwidmer commented 5 years ago

Hey @Carrrven, I am a little bit late to the party, but you could do the following:

$formItScriptProperties['fiarHtml'] = '<p>Your Email Text, link: <a href="http://your-domain.com?savedFormHashKeyField="' . $hook->getValue('savedFormHashKey') . '">Link Text</a><p>';

To make that work, the order of your hooks must be

$formItScriptProperties['hooks'] = 'FormItSaveForm,FormItAutoResponder';
Carrrven commented 5 years ago

Thanks @janwidmer I solved this problem by adding a variable in formitSaveForm. And then put a placeholder in the letter template.