PDA

View Full Version : Remember if a form has been filled in



aka Robbie
03-19-2007, 03:06 PM
I've never written cookies and am presuming that this is the way to solve my problem.

I have a page with a lot of information on it. What I am wanting to do is cut down on the amout of information first given and have a form to get the rest of the information. Once the form is completed and the submit button pressed the same page is loaded but without the form and displaying the extra information. I know how to do this via php so that is no problem.

The problem is that if someone has previously filled out the form to view the extra information and then come back to the same at a later date. Obviously I do not want to be requesting that they give their details again. So how can I set it up so that it checks to see if they have filled out the form, if not then the form shows, if they have then the extra information shows?

thetestingsite
03-19-2007, 03:15 PM
Well, you could use cookies (using Javascript or PHP). Another option (and a better idea I feel), would be to use a database. Cookies would probably be your best bet (unless the user deletes their cookies or the browser does not accept them).

Simple example (using PHP):

When the form gets submitted, it sends the info to a PHP script. Then, in that script (somewhere), it has this:



setcookie('CookieName', 'Data', time()+3600);


Then, to see if the form has already been saved, at the top of the form script, place this:



if ($_COOKIE['CookieName'] != "") {
donotShowForm();
}

else {
showTheForm();
}


(Of course, made up functions but you get the idea).

Hope this helps.

Locky
03-20-2007, 05:07 PM
Well, you could use cookies (using Javascript or PHP). Another option (and a better idea I feel), would be to use a database. Cookies would probably be your best bet (unless the user deletes their cookies or the browser does not accept them).

Simple example (using PHP):

When the form gets submitted, it sends the info to a PHP script. Then, in that script (somewhere), it has this:



setcookie('CookieName', 'Data', time()+3600);


Then, to see if the form has already been saved, at the top of the form script, place this:



if ($_COOKIE['CookieName'] != "") {
donotShowForm();
}

else {
showTheForm();
}


(Of course, made up functions but you get the idea).

Hope this helps.

i have been trying to create something like this basicly the same concept as yours but to hide the form i have to use JS and i am googleing how to put JS code into php then sorted

Locky
03-20-2007, 07:20 PM
javascript i am haveing no joy so i am just simply going to use php include and have 2 version of site, 1 with the form 1, without..