Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to auto submit a form

Status
Not open for further replies.

Dashley

Programmer
Joined
Dec 5, 2002
Messages
925
Location
US
Hi,
Im looking for a way to autosubmit (or autosave data) a form. I'd like to do it about everyfive minutes or so.

thanks
 

If you wanted to do it without annoying the user greatly you would need to use AJAX on a timer.

I'm assuming this is for when the user is writing a lot of text - maybe in a blog or similar ? if not then you must have one hell of a large (or complicated) form if the user will be there for periods of 5,10,15 minutes or more - if so, your time is probably better spent re-designing the form to be more usable and process in manageable steps.

If it is for when users write a LOT of text, then below is an outline of the general concept:

You'll need:
1. To set a timeout that calls a function every 5 minutes (client javascript).
2. To write a function that uses XMLHTTP/AJAX (Asynchronous Javascript and XML) which will read the form content, wrap it up into an XML document and call the remote 'save' function asynchronously using XMLHTTP (client javascript).
3. The remote save script will parse this content and save to a temporary place (e.g. database) (ASP)
4. Upon properly submitting the form the submitted data would be used to update the DB/whatever and the temporary data should be removed (ASP)
5. If this doesn't happen you need to check against the temp table everytime a user opens the form page and fill out the form with the saved data. (ASP)

There are a few things to consider on the way - but the general outline above should point you in the right direction. I suggest you get as far as you can, then post the relevant bits that you need help with in either this or the javascript forum.

A smile is worth a thousand kind words. So smile, it's easy! :-)
 
damber

thanks, sounds like great advice.
Actually its a very busy form. Its for medical/nursing students to put in their case work. They often run into problems when there called away and leave the screen up and for one reason or another loose data they really can't afford to and really hate to loose.

thanks again


 

If there is a lot going on then why not consider breaking it up into manageable steps - this will both achieve your requirement above and also make it easier for the users to navigate - and you can save each step in a simpler way. Just a thought.

A smile is worth a thousand kind words. So smile, it's easy! :-)
 
I agree with damber, breaking it up into easily saveable chunks might be better.

A big consideration is storing the information. If you have database fields that do not allow null values but tha part of the form has not been filled in yet, you have to put something in there. That means you have to check for that value later on to ensure that it actually gets filled in with correct information later.

You will also likely want to generate a unique ID for the data in the database to be able to link back to that data at a later time. If someone does not finish filling out the form and power to the computer is lost, someone closes the browser window or any similar event, you need to be able to recover that data for that person in it's current entry state.

For one of my own projects I created the form with two save modes, one as Save the other as Submit. Save mode creates a new record but does not perform all of the validation checks since some fields may be left blank and it stores the status in the record as well. Submit tests all fields to full specifications. When someone calls up a record stored in a save mode it displays that record accordingly and will not submit until all data is completed properly but will save in the edit state again.

Combine something like I did above with a timed automatic save and you may have a good solution.
You should probably make the timer reset itself if there is activity typing though so it will not interrupt data entry in order to do the timed save.
This might save you the need to save to a temporary record as well.



Paranoid? ME?? WHO WANTS TO KNOW????
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top