I’ve been tasked with writing a load/save function for a rather large form. This way the user can save their work and then come back later and load it and continue to work.
I’ve decided to use Server side storage and save the data locally to a mysql database. I figured out the ‘saveForm’, it simply stores $_POST as a long string into column.
I can’t figure out how to write the ‘loadForm’.
I have:
<form id="qa" .. ">
<button id="saveForm" type="submit"...">
<button id="loadForm" type="submit"...">
<input type="hidden" id="unique_user_id"...">
</form>
<javascript>
$('#saveForm').bind({
click: function() {
$.ajax({
type: 'post',
url: "/saveForm.php",
data: $("#qa").serialize(),
success: function() {
alert("form was submitted");
},
});
return false;
},
});
<javascript>
saveForm.php: (PHP & PDO)
// connect
insert into `saveQAForm` ($_POST['id'],var_export($_POST));
Do something like this:
loadForm.php
I feel it is important to pass a unique token or nonce that is unique to the user/session when retrieving the form so that another person couldn’t make a request for an ID and get that user’s personal information. Just a thought.