Checking if a form has been submitted.

C

clarket

Hi,


I have a html form where all the details are saved in a MySQL database
that uses PHP to insert the data into the database.


The problem I'm having is that if people dont submit the form then the
data doesnt get saved to the database.


Does anyone know a way to show a message e.g. "Form has not been saved"
if the user tries to exit the page without pressing the submit button?
or does anyone have an example of this?


Thanks,


Tony.
 
C

c.anandkumar

clarket said:
Does anyone know a way to show a message e.g. "Form has not been saved"
if the user tries to exit the page without pressing the submit button?
How does a user 'exit' a page? If you had meant clicking on other
links, then add a handler to all your links. This can be tedious if you
have a lot of links - unless you have a good editor - you could change
a link like this - <a href="http://www.something.com">... to something
like this - <a
href="javascript:dataNotSaved('http://www.something.com')"> and
function dataNotSaved(url) {
alert('Data not saved');
document.location.href = url;
}
If you have links that open a new window, or load a page in a frame,
then you could handle it by having an ID to each anchor tag, finding
the 'target' attribute of the element and loading the URL
appropriately.
 
D

Darkstar 3D

Use an onClose or onUnload (whatever its name) event set to fire if a
certain event hasn't happened or variable isn't set. Have your submit
button set the variable, and onUnload check for it. Googling, it seems
that it is onunload and onclose.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top