473,569 Members | 2,542 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to avoid resubmitting the form in php

2 New Member
how to avoid resubmitting the form in php
Sep 8 '08 #1
4 2539
nathj
938 Recognized Expert Contributor
On the click of the button remove it or change the caption and make it non-clickable.

Loads of places do this, experiment with the idea.

nathj
Sep 8 '08 #2
bnashenas1984
258 Contributor
Hi
Yes that works some how but the problem is that people can still click on refresh button and resubmit the form..
I think the best idea is to do it on server side. Like checking for information in database. I mean if it's a registration page then you can check if the username allready exists. Or if it's a normal form then you can make a HIDDEN input and give it a random value then when user submits the form you can put the random number on the database and check for the existing numbers in the database each time a form is submited.

I'm sure there are other options you can use but client side scripting is not a good idea

Good luck
Sep 8 '08 #3
nathj
938 Recognized Expert Contributor
Of course server side verification should be considered.

Another option for this would be to use the $_SESSION. You could store the submitted info in the $_SESSION and check that when the form is submitted.

This is what I would do in conjunction with my earlier post.

Cheers
nathj
Sep 8 '08 #4
FLEB
30 New Member
The session-variable idea sounds the cleanest, to me. Create a session variable with a random or sequential "Transactio n ID". Then, write the ID into the form in a HIDDEN variable.

[PHP]
session_start() ;

// Generate a $this_tid variable however you want to...

$_SESSION['tids'][$this_tid] = true;

// and when you are building your form, insert the tid field...

echo '<input type="hidden" name="tid" value="'.$this_ tid.'" />';

[/PHP]

When the form is submitted, check whether the submitted transaction ID matches any in the session variable, and fail if it doesn't. If the session does
exist, delete the associated transaction ID variable and take action on the submission.

[PHP]
session_start() ;

if ( array_key_exist s($_POST['tid'], $_SESSION['tids'] ) {
unset( $_SESSION['tids'][ $_POST['tid'] ] ); // expire the tid by deleting the array entry.
// Do stuff here
}
else {
echo "You cannot submit this form twice!"; // (and other such user-directed anger)
}
[/PHP]
Sep 8 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2438
by: Nathan Sokalski | last post by:
When form data is submitted to an ASP page using the POST method, it is not visible in the URL, but it is still resubmitted if the user clicks the Refresh button. This can cause statistical data to be accidentally submitted multiple times, making the results incorrect. I would like like the user to be able to click the Refresh button without...
3
2082
by: serge calderara | last post by:
Dear all, I have a vb.net application which start with a sub main procedure. inside this sub main procedure I create a and instance from an assembly x like as follow: sub main() ..... Application.Run(New frmLogin) end sub
12
4410
by: Steve Jorgensen | last post by:
Since reading values from calculated controls in Access 2000 and 2002 from code has proven unrliable at best, and since I like to avoid running separate queries to calculate sums of subform records since they can give inconsistent results if there's more than on interface or user with access to the table, I wrote code to loop through a...
11
1667
by: Johnny M | last post by:
I have several databases where I have one form to add a new record and one form to edit an existing record. I use unbound forms and class modules most of the time. What I would like to do is have one form that handles both adding a new record to the database and editing the same type of record. The form would be altered in the load event...
6
7342
by: Lasse Eskildsen | last post by:
Hi, How can I make sure I don't show the same form twice? If the form is already shown, just focus. I tried using ownedforms, but can't quite make it work... Thanks in advance! -- Lasse
2
1730
by: Deano | last post by:
Hi, I have created a new form that reads in data from some intermediate tables. These intermediate tables are used to compile data for use in a report or the new form I have made. Having opened the new form with this intermediate data (it provides an aggregate view of various top-level codes in column A) the user can view and add...
6
6507
by: planetthoughtful | last post by:
Hi All, I have a C# ASP.NET page that submits back to itself to insert details from a form into a database table. When / if the user refreshes the page (and gets the standard warning that POST data will be resubmitted), the previously submitted record is sumbitted again, and a duplicate record is inserted into the table. In PHP I would...
3
1111
by: Ian Davies | last post by:
Hello does anyone know how I can retain values of a radio button and text in a text box on a page when I use $_SERVER to requery a page? Im sure Ive seen this done before but cant find the code Thanks Ian
4
4748
by: R.A.F. | last post by:
Hi, Basically i've read that under C++ we can avoid flickering forms during sizing (maximize, minimize, restore,...) in SDi/MDI application. I understood that for that i need to override the WndProc with WM_PAINT and WM_SIZE messages. however, under MFC there is a useful method called SetRedraw(bool); it allows or not, to redraw the...
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7676
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.