473,473 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Preventing multiple form submissions

I have an interactive web page that I need to prevent refreshes on.
The problem is that I want to ALLOW resubmissions, but only via the
submit button. My web page has two forms on it, one form for adding
users, and one form for removing users. I want to be able to add a
user, click the submit button, add another user, click the submit
button again, and so on, BUT, disallow adding a user and then hitting
refresh (which would add the same user again) Any ideas on how to do
this??

Thanks.

Matt Williams

Jul 17 '05 #1
7 2100
Matt wrote:
I have an interactive web page that I need to prevent refreshes on.
The problem is that I want to ALLOW resubmissions, but only via the
submit button. My web page has two forms on it, one form for adding
users, and one form for removing users. I want to be able to add a
user, click the submit button, add another user, click the submit
button again, and so on, BUT, disallow adding a user and then hitting
refresh (which would add the same user again) Any ideas on how to do
this??


Redirect immediately after inserting the record to the same page but
pass a parameter so you know to notify the user of a successful insert
eg header('Location: filename.php?message=success'); where filename.php
is the name of your script with the form on it. That way if you hit
refresh you're just getting the form and success message instead of
inserting the message agin.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #2
Excellent suggestion, but I have other preliminary PHP code (queries)
executing beforehand. Headers can only be modified if they are the
first thing within the script, otherwise errors are thrown. I ended up
fixing this problem in the same way in which you suggested, but using a
javascript redirect nested at the bottom of my php code. Thanks for
the help.

Matt Williams

Jul 17 '05 #3
On 17 Jan 2005 00:04:14 -0800, Matt <md*******@radford.edu> wrote:
Excellent suggestion, but I have other preliminary PHP code (queries)
executing beforehand. Headers can only be modified if they are the
first thing within the script, otherwise errors are thrown. I ended up
fixing this problem in the same way in which you suggested, but using a
javascript redirect nested at the bottom of my php code. Thanks for
the help.


Don't use JS redirects. Just enable output buffering (ob_start())
and you can set headers anytime.
Besides queries themselves don't output anything, so you could reorganize
code a bit to complete all actions before outputting anything.

Remember that you MUST set 303 response status when you redirect POST
request.
header('HTTP/1.1 303 Redirect');
--
* html {redirect-to: url(http://browsehappy.pl);}
Jul 17 '05 #4
porneL wrote:
Remember that you MUST set 303 response status when you redirect POST
request.
header('HTTP/1.1 303 Redirect');


Although 303 is a more logical choice here, nothing stops
you from sending a 302 response. So make that 'MUST' a
'can', or a 'should' if interoperability with older software
isn't an issue, and I'll second that.

--
Jock
Jul 17 '05 #5
>> Remember that you MUST set 303 response status when you redirect POST
request.
header('HTTP/1.1 303 Redirect');


Although 303 is a more logical choice here, nothing stops
you from sending a 302 response. So make that 'MUST' a
'can', or a 'should' if interoperability with older software
isn't an issue, and I'll second that.


Right. It is actually SHOULD in RFC terminology.

But it is very important in this case, because current User-Agents
post form *again* on 301/302 status, so such redirect would *cause*
re-post instead of preventing re-post.

Only user-agent I know that doesn't understand 303 is Netscape 4.

Because 303 reponse may have a body and you can put link there,
you can have 100% compatibility (with extra "click here" for lousy UA).
--
* html {redirect-to: url(http://browsehappy.pl);}
Jul 17 '05 #6
porneL wrote:
Remember that you MUST set 303 response status when you redirect POST
request.
header('HTTP/1.1 303 Redirect');

John Dunlop wrote:
Although 303 is a more logical choice here, nothing stops
you from sending a 302 response. So make that 'MUST' a
'can', or a 'should' if interoperability with older software
isn't an issue, and I'll second that.

porneL wrote:
Right. It is actually SHOULD in RFC terminology.
No, it's not; at least not in RFC2616. The RFC defines the
status code, but doesn't tell you when to use it.
But it is very important in this case, because current User-Agents
post form *again* on 301/302 status,
With a 301, that's what's supposed to happen. What browser
continues POSTing after a 302?
so such redirect would *cause* re-post instead of preventing re-post.
RFC2616 notes, sec. 10.3.3:

| RFC 1945 and RFC 2068 specify that the client is not
| allowed to change the method on the redirected request.
| However, most existing user agent implementations treat
| 302 as if it were a 303 response, performing a GET on the
| Location field-value regardless of the original request
| method. The status codes 303 and 307 have been added for
| servers that wish to make unambiguously clear which kind
| of reaction is expected of the client.

http://www.ietf.org/rfc/rfc2616.txt
Because 303 reponse may have a body and you can put link there,
you can have 100% compatibility (with extra "click here" for lousy UA).


Nothing stops you from providing a note along with a 302
response; in fact the RFC says you should (and that's a
'SHOULD'), unless the request method was HEAD.

I was never disagreeing with the sending of a 303, but I
thought your 'MUST' deserved a comment.

--
Jock
Jul 17 '05 #7
porneL wrote:
On 17 Jan 2005 00:04:14 -0800, Matt <md*******@radford.edu> wrote:
Excellent suggestion, but I have other preliminary PHP code (queries)
executing beforehand. Headers can only be modified if they are the
first thing within the script, otherwise errors are thrown. I ended
up fixing this problem in the same way in which you suggested, but
using a
javascript redirect nested at the bottom of my php code. Thanks for
the help.


Don't use JS redirects. Just enable output buffering (ob_start())
and you can set headers anytime.
Besides queries themselves don't output anything, so you could
reorganize code a bit to complete all actions before outputting
anything.

Remember that you MUST set 303 response status when you redirect POST
request.
header('HTTP/1.1 303 Redirect');


The 303 redirect was really useful information and helped out with an
admin system I am putting together at the moment where I redirect them
after the form is posted, so thanks.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #8

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

Similar topics

3
by: shortbackandsides.no | last post by:
I've been having trouble preventing users pressing Enter part way down a form so the incomplete form gets submitted. I came up with a possible solution - the code below seems to work in both...
12
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
1
by: Adam Smith | last post by:
Have a lot of data to collect / choices presented, producing a large form. I am desirous of breaking it up into multiple pages to avoid detracting users. Could some one say how best to create...
4
by: Diane Selby | last post by:
Hi- I am developing an ASP.NET application that can take a few seconds to process the request from the user. We are looking for a client-side solution that will prevent users from resubmitting...
3
by: Mark | last post by:
This is a solution... Often users want to keep clicking "submit" when they are waiting for server processing. Most apps these days like to disable the submit button to prevent this. You can't just...
0
by: Marc DVer | last post by:
I am at kind of a loss on how to design a certain database project I am working on. Basically, we have a proprietary program with a standard backend (though we do not have direct write access to...
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...
9
by: Ned White | last post by:
Hi All, Im my c# web project, users click a submit button for credit card payment process. On the web server side ( on ButtonClick_Event) the user's input(name,date,cc number etc.) is processed...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.