Page 1 of 1
Saving & resuming a partial form
Posted: Mon Oct 31, 2011 9:53 pm
by GeorgeMcKnight
Hi everyone,
Sorry for the first time post… I can't even admit to being a long-time lurker. I've been asked to put together a form for a client, and decided to code it in PHP (a language I've never used before). But now I'm stuck, and Google's not helping!
My form is long (70+ questions). My users need to be able to save their work, login again, and continue where they left off. They'll only submit once all the questions are complete.
As an example, say User 1 logs in. He'll be presented with 70 questions. On Day 1, say he gets through 30 questions, and then clicks "Save Form". On Day 2, he logs in again, and see questions 1-30 already filled in. He complete questions 31 - 50, and clicks "Save Form" again. Finally, on Day 3 he logs in for a final time, and completes questions 50-70.
The final submit will of course have all the data.
I hope that's clear. Please help if you can. Anything will do - code snippets, links, etc.
Re: Saving & resuming a partial form
Posted: Mon Oct 31, 2011 11:47 pm
by social_experiment
Depending on how many users have to do this everyday you have two options; a flatfile system where the saved data is written to a file or a database option where data is saved to the database and the retrieved.
Does the user have to login again to continue working on their form?
Re: Saving & resuming a partial form
Posted: Tue Nov 01, 2011 2:07 am
by Christopher
GeorgeMcKnight wrote:My form is long (70+ questions). My users need to be able to save their work, login again, and continue where they left off. They'll only submit once all the questions are complete.
You have clearly described the Domain of the problem (a 70+ question questionnaire) and necessary functionality (logging-in and filling out a pre-populated form). social_experiment has mentioned several ways to store this data. Typically, you would create a class to represent the information in the questionnaire. That kind of class is often called a Model because it models something in the Domain. So you would create this class named something like QuestionnaireModel and it would have an interface from which your form could get any previously submitted values, and an interface to allow data from the submitted form to be given to the class so internally it can save it in some kind of datasource. This provides some clear separations between the form itself, the representation of the questionnaire in the code, and how the actually data is stored.
How much of this system have you already written? Do you have the user account part done yet?
Re: Saving & resuming a partial form
Posted: Tue Nov 01, 2011 7:25 am
by GeorgeMcKnight
Thank you. I appreciate you taking the time out to help me.
Currently, I have just the form built out. On submit, the form data is saved onto a MYSQL database. When I first started coding, I downloaded a trial piece of code that provides authentication functionality. It's not directly tied to my form, but rather allows an authenticated user to access my site, which has a link to my form.
Each user is required to login again to continue working on their form. There will be at maximum 150 users using the form. (and likely, only about 1/2 that). How would the flat file / DB system work in theory?
Is the idea that when the user clicks "Save Partial Form", their data gets stored into a temp table? If so, how would I retrieve the data and pre-populate their form when they log in the second time?
Thanks again..
Re: Saving & resuming a partial form
Posted: Tue Nov 01, 2011 7:40 am
by social_experiment
GeorgeMcKnight wrote:How would the flat file / DB system work in theory?
Scratch the flat file idea, with that much users (even half of 150) a flat file system wont work.
The databasis system would be along the lines of this simple example:
1. User logs in; this is a new user (user A)
2. User A works up to question 25 then quits.
3. User A's name (or session id | something unique to the user) is written to the database, along with the information saved.
// 1 day later
4. User A logs in
5. A check is done to see if user A has entered any data and if so, populate the form with the data.
6. Process repeats until 70 questions are completed
GeorgeMcKnight wrote:Is the idea that when the user clicks "Save Partial Form", their data gets stored into a temp table?
It is an option but i don't know if that would be a good design, once the data is saved (in the final step) if you are using one table, the data is written to the table. If you have a temporary table data has first to be retrieved, then written back to the main table. Or you could have a function linked to the 'Save complete button' (if you have something like that) and when that is clicked write the complete from to the database. The biggest consideration imo is that you have 75 users doing simultaneous work on the database which might slow things down
Hth
Re: Saving & resuming a partial form
Posted: Tue Nov 01, 2011 7:07 pm
by Christopher
GeorgeMcKnight wrote:Is the idea that when the user clicks "Save Partial Form", their data gets stored into a temp table? If so, how would I retrieve the data and pre-populate their form when they log in the second time?
Yeah ... I would just have a "Save" button and have the form load any saved data every time they go to the form. You can easily look up the data because the person is logged-in -- so you have their User ID. Save the User Id in a field with the form data and load it with that.
Re: Saving & resuming a partial form
Posted: Wed Nov 02, 2011 12:43 pm
by internet-solution
GeorgeMcKnight wrote:Is the idea that when the user clicks "Save Partial Form", their data gets stored into a temp table?
I do not even need a temp table. Just add an integer column to existing table - say `status` - where you can store 0 for partial save and 1 for full save.