tags:

views:

53

answers:

2

Hello all,

I have designed a user profile form, a long form which is quite complicated. Before the user can submit and save it, the form needs to be validated.

Here is the question:

When the form is saved into the DB, there are multiple tables involved. Now I would like to introduce a function called "Save Form" which internally doesn't validate the form and just save whatever the user entered.

How can I do this? There are potential issues, such as :

Q1> How to save temporary data?
Q2> What should I do if the user saves the temporary data 
    without submitting the form and then quit. 
    This feature looks like the Draft feature provided by Gmail.

Thank you

+5  A: 

Q1> How to save temporary data?

There are a couple ways you could do this. You could save it to a different table. You could also (probably more popular) save it to the same table as the completed profiles, but flag it as incomplete via a column for this purpose. This column could be named complete. If the profile is not complete, it would be set to 0 or false. If it is complete, it would be set to 1 or true. You can then query based on it.

You could then "validate" the data via whatever procedure is required and set the column to 1 or true as needed.

Q2> What should I do if the user saves the temporary data without submitting the form and then quit. This feature looks like the Draft feature provided by Gmail.

The answer above should serve this purpose as well.

If you need to reload the data and allow the user to continue filling out the incomplete form, you will need to get some sort of identifier from them to allow this. You could do this by setting a cookie, or by some sort of unique identifier they would enter at the top of the form - such as SSN, phone #, student ID #, etc (or a combination).


If you are looking for a feature like Gmail's draft feature, you will need to implement some sort of AJAX call that automatically fire's every X seconds/minutes to automatically save the data.

Nate Pinchot
+1  A: 

You could create a session for the fields your interested in saving. For example

$this_form = array(
  'field1' = 'value',
  'field2' = 'value2',
);

Then save this to a session:

$_SESSION['this_form'] = $this_form;

If you want to be really lazy you could just save the $_POST or $_GET variable in the session.

$_SESSION['my_post'] = $_POST;// or $_GET depending on your form.

And Of course you know not to do anything with these until you validate them and do the usual inoculations.

You can retread the saved session variable later simply by calling calling it.

i.e.

echo $_SESSION['this_form']['field1'];

Once you are done with the session you can delete it with the unset command:

//i.e.

unset $_SESSION['this_form']

There are also session functions that you can use:

http://us3.php.net/manual/en/ref.session.php

DKinzer