I currently have a form that is multi-step; it doesn’t do anything fancy per step, it simply does display: none
on the previous step to hide the previous fields and move the user forward.
It submits via AJAX and has required fields.
Is there any way to capture the data from each step of the form, and then, if the user drops off or never submits the form, send the captured data – I’m not worried about any issues in regards to data protection, as it doesn’t apply in this situation.
The form basically looks like this:
<form>
<div class="step-1">
<label>First Field
<input type="text" id="field1" name="field1" maxlength="50">
</label>
<label>Second Field
<input type="text" id="field2" name="field2" maxlength="50">
</label>
<a href="#" class="next-step">next step</a>
</div>
<div class="step-2">
<label>Third Field
<input type="text" id="field3" name="field3" maxlength="50">
</label>
<label>Fourth Field
<input type="text" id="field4" name="field4" maxlength="50">
</label>
<input type="submit" id="send" name="submit" />
<span id="submitdata"></span>
</div>
</form>
The bit I’m struggling with is knowing when the user drops… Does it need to invoke some kind of session per the form?
2
Answers
Try this code:
You could automatically submit the form when the user leaves the page, using the beforeUnload event:
If you need to record that it is a ‘by default’ submission, then you could use a hidden form element instead of the variable notSubmitted. The hidden element would give you that data in the form.