Solved

Stop Form from Submitting Again on Refresh or Back Button

Posted on 2003-10-22
5
188 Views
Last Modified: 2013-12-24

How do I get a form to stop resubmitting when the user presses refresh or the back button?
0
Comment
Question by:champ_010
  • 3
5 Comments
 
LVL 11

Expert Comment

by:hart
Comment Utility
be more specific, have u written the code for updation or insertion on the same page along with the form or what???

Regards
Hart
0
 
LVL 17

Expert Comment

by:anandkp
Comment Utility
run this code on ur PC & click 2wice on the button & let me know - if it works the way u want it to !

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"><!--
var myvar = false;    
function chk_duplicate_submit()
{      
    if(myvar)
    {
          alert("pls be patient - while we process ur request !");
           return false;
    }
     else
     {
        myvar = true;
        document.frm.submitme.value = 'Processing ...';
     }
}

function chkForm()
{
    return chk_duplicate_submit();
    // my general form validations here
}
//-->
</SCRIPT>

<FORM name="frm" action="somepage.cfm" method="post">
     <INPUT type="text" name="myname"><!-- more form elements here -->
     <INPUT type="button" name="submitme" VALUE="Continue ..." onclick="return chkForm()">
</FORM>

let me know ....

K'Rgds
Anand
0
 
LVL 11

Accepted Solution

by:
hart earned 100 total points
Comment Utility
see if u have form that gets submitted to a another page and there itself if u r displaying some things.
then on back button or refresh there will be an alert stating do u want to post the data or not...

so to avoid this the proper way of doing things is this..

say u have form on a page

<form name="frm1" method="post" action="amd_somepage.cfm">
</form>

submit this form to an intermediate page amd_somepagename.cfm [amd is short for add/modify/delete]
there do the appropriate updates or inserts or deletes [with data base]
and then using <cflocation  tag send the user to the next page.

thsi way even if the user refreshes the final page it would never alert u anything :-)

hpe its clear :-)

Regards
Hart
0
 
LVL 1

Author Comment

by:champ_010
Comment Utility

hart, sorry i read your last post wrong--i think you are saying if i submitt to another page to do the processing--i can cflocation back to the first page that one that the form is one--and that way i can avoid the refresh back button right?
0
 
LVL 11

Expert Comment

by:hart
Comment Utility
yes if u keep an intermediate page to add modify or delete in the database and then redirect the user to appropriate page then the problem of an alert occuring on refresh will not occurr.

hope its clear

Regards
Hart
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now