473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Idea for form action page to reduce double submissions

Hi,

I have been trying to come up with an idea to reduce double submissions
where a user clicks refresh and, for example, another row is INSERT
into a table.

Originally, I would have a form page. When a user submits the form (ie.
index.php), I would script it so that when the form action would be the
same page but it would use the address 'index.php?action=add'. This is
bad (mmm-kay) as when the user refreshes the page it would add another
row into the database table.

The solution (thanks to a reply on this newsgroup) is to have a
different page to carry out the form processing and depending on the
result either redirect them to a successful or unsuccessful page (or
the same page but different outcomes as a result of scripting).

Anyway, my idea is very similar to the above where a user will fill in
the form. They will then be submitted to a page called action.php. This
action page will deal with all scripting associated with this news
admin system I am planning, including add/edit/delete pages. They will
be dealt with by passing the rellevant instruction with the GET
parameters (ie. action.php?action=delete). Should an error be found
then it will be highlighted in the action page and a link back to the
form page will be provided with the values entered passed back using
POST variables. In the event of a successful entry, the user will be
redirected back to the form parent page (view article (parent) -> edit
article (child)) with passed GET info (ie. view.php?action=add) where
as it knows what action was carried out it can assume that it was
successful and the 'You have successfully added a news article' message
would be displayed.

Im pretty confident that this system would be a big improvement but
would be greatful if anyone who does this in a similar way would give
comment. Cheers

Burnsy

Aug 4 '05 #1
5 3749
After a submission is sent I repond with a page that loads the new page a
redirect I guess.

example:

str="/z/sn?command=cashflow&rec="+dynvar["index"]
page="<body onload=\"window.location.replace('"+str+"');\">"+" <a
href=\""+str+"\">Cash Flow</a><BR><BR>"+chr(13)+page+"</BODY>"

basically the onload window.location.replace returns the browser to a fresh
page which will not enter a new record if refresh is clicked good luckOak
<bi******@yahoo.co.uk> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi,

I have been trying to come up with an idea to reduce double submissions
where a user clicks refresh and, for example, another row is INSERT
into a table.

Originally, I would have a form page. When a user submits the form (ie.
index.php), I would script it so that when the form action would be the
same page but it would use the address 'index.php?action=add'. This is
bad (mmm-kay) as when the user refreshes the page it would add another
row into the database table.

The solution (thanks to a reply on this newsgroup) is to have a
different page to carry out the form processing and depending on the
result either redirect them to a successful or unsuccessful page (or
the same page but different outcomes as a result of scripting).

Anyway, my idea is very similar to the above where a user will fill in
the form. They will then be submitted to a page called action.php. This
action page will deal with all scripting associated with this news
admin system I am planning, including add/edit/delete pages. They will
be dealt with by passing the rellevant instruction with the GET
parameters (ie. action.php?action=delete). Should an error be found
then it will be highlighted in the action page and a link back to the
form page will be provided with the values entered passed back using
POST variables. In the event of a successful entry, the user will be
redirected back to the form parent page (view article (parent) -> edit
article (child)) with passed GET info (ie. view.php?action=add) where
as it knows what action was carried out it can assume that it was
successful and the 'You have successfully added a news article' message
would be displayed.

Im pretty confident that this system would be a big improvement but
would be greatful if anyone who does this in a similar way would give
comment. Cheers

Burnsy

Aug 4 '05 #2
I've been able to combat this problem with something like this
(requires the use of sessions):

1. When a page is loaded, generate some random id and store it in the
session as curpage_id. (Also do step #3).

2. When drawing a form, include a hidden parameter called page_id or
something and use the curpage_id as the value.

3. On the next page, put the curpage_id from the session into another
session variable called prevpage_id, and generate a new curpage_id.

4. Before processing your form (inserting rows, whatever) check that
the form parameter page_id equals the value of prevpage_id from the
session. If they do, you're good. If they don't the page must have
been refreshed.

Aug 4 '05 #3
ZeldorBlat wrote:
I've been able to combat this problem with something like this
(requires the use of sessions):

1. When a page is loaded, generate some random id and store it in the
session as curpage_id. (Also do step #3).

2. When drawing a form, include a hidden parameter called page_id or
something and use the curpage_id as the value.

3. On the next page, put the curpage_id from the session into another
session variable called prevpage_id, and generate a new curpage_id.

4. Before processing your form (inserting rows, whatever) check that
the form parameter page_id equals the value of prevpage_id from the
session. If they do, you're good. If they don't the page must have
been refreshed.


Doesn't this preclude the possibility of the user having multiple
windows open, and still being able to use your website? This would be awful.

Cheers,
Nicholas Sherlock
Aug 4 '05 #4
First of all, I don't care too much about my users since most of them
(that use the forms anyway) are my co-workers.

You are correct that this could be a problem. What would need to
happen is as follows:

Someone opens a page with a form.
Someone opens another page in a different window/tab.
Someone returns to the original form and tries to submit.

Nobody has complained about it yet (although they might). Since you
think that "this would be awful," perhaps you can suggest an
alternative?

Aug 5 '05 #5
ZeldorBlat wrote:
Nobody has complained about it yet (although they might). Since you
think that "this would be awful," perhaps you can suggest an
alternative?


Don't use sessions. I haven't tried this out, but how about this:

Say you have an action like making a post on a forum. You want to stop
people from pressing refresh or double clicking submit, but a large
percentage of users will be viewing/working on more than one post at a
time (Tabbed browsing). You have decided that a "time delay" system is
unacceptable for your users. You have the structure "New post page"
(Where your form lives) ->"Action page" (Which does the processing).

Store a global lastpostid counter in your database. Every time the new
post page is loaded, this id is incremented and written to a hidden
field in the form.

Store this id into every new post made. Then, if the action page
receives a post id from the hidden field which is already part of a post
in your database, the user has refreshed or double clicked. No time
delays, the users can use tabbed browsing.

Cheers,
Nicholas Sherlock
Aug 5 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
15
by: M Smith | last post by:
I have a form I want to submit to itself. I want to be able to type in a list of numbers and submit the form and have that list show up on the same form under the text box I typed them into and...
7
by: degmsb | last post by:
With Java script when a user hits submit on a form on my site, is it possible to take the values from the form and submit them to another form on another Url without the user who submitted the form...
4
by: kschneider | last post by:
Assume there's a form with it's action attribute all set to post to a URL, but without a submit control. Form submission is done via a link and I want to prevent the classic "double submit"....
6
by: Oleg Konovalov | last post by:
Hi, I have a Java/JavaScript GUI application where I perform a lot of long DB operations , which takes 5-60 secs to perform. Sometimes user double-clicks the button or just gets impatient and...
9
by: mosscliffe | last post by:
I am struggling to find a python example of the scenario - I have. I have a python script, which generates a page with a search button (actually an input field). The data from the above...
1
by: chromis | last post by:
Hi, I'm having trouble fully implementing the edit section of a contact admin system, so far I have written the following: - Bean (Contact.cfc) - Data Access object (ContactDAO.cfc) - Gateway...
14
by: Ed Jay | last post by:
Despite searching the net, I can't find a suitable solution that prevents a user's double click from submitting a form twice. I'm currently using the following in a button element: <input...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.