Page 1 of 1

Saving Form

Posted: Wed May 07, 2014 8:02 pm
by unknown365
I'm quite new to PHP. I'm having a problem with my forms wherein if I submit a form and if (1) my internet suddenly went down (2) a brownout suddenly occurred, everything encoded in the form will be lost. Is there a way for me to automatically save the form if it is not submitted? Is it a good idea to do so?

Thanks for your help

Re: Saving Form

Posted: Wed May 07, 2014 8:17 pm
by requinix
Whether you should worry about it or not depends on the situation. Is it a big long form? Takes a long time to fill out? Might the user be continuously working in this form for a long time without submitting it? What's the impact of losing the data?
There are a few solutions:
a) Javascript that uses HTML 5 features to save the data to the user's computer. Don't know if I've ever actually seen any in use.
b) Javascript which does asynchronous saving by sending your server bits of data as the user goes through the form. Like saving drafts.
c) Multiple smaller forms.

It's only really the specialized forms that need this kind of treatment. Most commonly that's some kind of document editor and the autosaving functionality is especially useful. Otherwise it's not really something most people think about.

Re: Saving Form

Posted: Wed May 07, 2014 10:25 pm
by unknown365
Yes, it is a long form. Basically, the form is used for the sales made by an agent per day which has around 100-150 on the average. There are times when it even exceeds 200. What do you think I should do? I need a suggestion from someone who have more experience than me.

Also, the form I made has an inventory incorporated to it. What typically happens to the form when in the middle of processing: (1) the browser was intentionally closed, or (2) the internet suddenly went down? Because there are times when the form does not get submitted but the inventory is deducted. Is this normal or was there something wrong with my code?

For your information in my code, I deduct the total sales immediately before I insert the records one by one in the database. Should I deduct the inventory one by one as the record is inserted in the database? I actually did the current logic so that the program would only access the database once instead of accessing the database each time there is a record (which usually has 100-150 on average).

Re: Saving Form

Posted: Wed May 07, 2014 11:30 pm
by requinix
If the browser is closed, or anything else causes the browser to be closed (shut down, power outage, whatever) then the data is lost. It was only in the browser's memory and once it's gone, it's gone.

If your script is doing anything then the form was submitted. After all, if the form wasn't then how could your code know what to do?
If the code is, say, deducting but not inserting some particular inventory then there's a problem with the code - not the form. Maybe it's trying to insert duplicate data, or maybe the data has something that's messing up the query, or one of a number of possibilities.

Your first step is to reproduce the problem. What data is the person entering that is only getting half-processed? Once you know that you can start to figure out why the code had problems dealing with it.
While you're working on that, how about posting the code? Maybe there's something that will stand out to us.