By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,841 Members | 854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,841 IT Pros & Developers. It's quick & easy.

Idea for form action page to reduce double submissions

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.