Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I disable the Back button on a form?

Status
Not open for further replies.

NoWayIsThisInUse

IS-IT--Management
Jul 16, 2002
79
US
I've looked through the FAQs and couldn't really find the answer to this. How do I disable the Back button when I'm on a particular form? I don't want the user to leave the form without either clicking on Submit or Cancel.
I think I need to use Javascript and redirect back to the current form... but how is this accomplished?
 
Take it to Forum216 (Javascript)..

You don't need to mention any cold fusion use... but if there's anyway, they'll know.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
It's not easy. You can't disable the button, you have to remove the menu then you have to disable the backspace key, then disable the right click (there is a back option in the menu) and even then people can still ctrl+n to get the full menu in a new browser window.

That's just in IE i don't know methods from other browsers.

like webmigit says it's easier answered in the JS forum but don't get your hopes up.

A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
and that all relies on someone not browsing up to your page with java/js turned off.

 
Um, duh, I just thought of this, you could make the form a popup window... since its the first page they couldn't go back from it.

There's not really a need to worry about someone disabling javascript... there's really two types of people online.

Those who don't understand very much about the internet.. since javascript is already enabled.. they don't disable it.

And those who understand a whole lot about it who are usually on heavier sites where the sites sort of fall apart without js.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
the best way to solve this situation is to design your application so that it does not matter if the user does something other than pressing Submit or Cancel

it's kind of a zen thing

see also Don't do that then!

rudy
SQL Consulting
 
Yeah, I thought about the popup window after I submitted this question, too. And Rudy is really correct in saying to design it so that it doesn't matter. What my problem really is is that I have a two-step form... one form leads to the second. People do the first form and I'm inserting a header record, then they get to the second page and fill some of it out and then click on the back button for whatever reason and then click forward and try to save and it doesn't.
So I really just don't need to insert until they submit on that second page. (I should just do a stored procedure w/multiple inserts.)
Thanks everyone for your suggestions.
 
Now that you've explained it, I (and I'm sure others) can recommend other ways to go about it.

Someone may be hitting back to correct a mistake, so is it a problem to let them.. you could let the new record be the primary and delete the first save record.

If you have a unique ID available for it... (like each user gets one header and report, then you could use something like this).

Code:
<cfif isDefined("form.FieldNames")>
  <cfquery datasource="#dsn#">
    delete [red]*[/red] from headers
     where userID = #cookie.userID#
  </cfquery>

  <cfquery datasource="#dsn#">
    insert into headers(userID,name,stuff)
    values('#cookie.userID#',....)
  </cfquery>
</cfif>

That would work... and there are other solutions...

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
TT's running a bit slow but I just thought of this...

Along with my example above, you could have a status field so that even if the user could have multiple headers, it was a one-at-a-time process...

Just do this

Code:
<cfif isDefined("form.FieldNames")>
  <cfquery datasource="#dsn#">
    delete [red]*[/red] from headers
     where userID = #cookie.userID#
       and saveStatus = 0
  </cfquery>

  <cfquery datasource="#dsn#">
    insert into headers(userID,saveStatus,name,stuff)
    values('#cookie.userID#',0,....)
  </cfquery>
</cfif>

And then on the page that processes your second form.. you can run a query to update the status so it is no longer zero.

BTW, the * (in both posts) is red because you may need to remove it or keep it depending on your db engine.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
if you really need multiple page forms, save the form info into into session or cookies

page 2 of the form saves page one info to cookies, page 3 of the form saves page 2 info to cookies etc. the insert /update /action page uses the saved cookie info to save data. this way the user can even go back and edit previous pages if needed. you can display the cookie info for each form field if it exists, so a go back would simply take them to the previous page with old info filled in, even if they refresh. I don't like to save data to the db unless its all there and ready to go.

you can even have the acion/db insert page save the last form page into cookies, so that if there is an error on the last page, the user only has to enter the incorrect info, not all over again. just before you save info to cookies from the previous form, do any error checking for form values, send back to fix them if needed.


 
if you really need multiple page forms, save the form info into into session or cookies
There's no way I would try this on an application that used a lot of forms, I've come behind too many developer who tried this and it was a nightmare when they didn't clear the sessions/cookies!

When I pass form info from one form to the next form, I do it with...FORMS! I may be thinking out of the box here, but when I submit form 1 to form 2, I just store everything from form 1 as a hidden value in form 2. It's a snap using this awesome little snip of code from webmigit.
Code:
<cfoutput>
  <cfloop list="#form.fieldnames#" index="f">
    <input type="hidden" value="#jsstringformat(FORM[f])#" name="#f#">
  </cfloop>
</cfoutput>
Stick this in every form that comes after the first one, and it will take the form values from the previous form and store them as hidden form fields. Then you just wait until the last form page is finished to insert into the DB. It doesn't matter if you have 2 forms or 200 forms, all values will be added and passed to the next page until you're finished. Cool, huh? [thumbsup2]



Hope This Helps!

Ecobb
Beer Consumption Analyst

"My work is a game, a very serious game." - M.C. Escher
 
Thanks for the nod.

I agree... save as little to sessions as possible.. It can kick you in the rear if you're not careful.

My way here is kind of cheap but I think it has a lot of promise... if the sessions times out the information is still saved.

And like I said before, the user can still correct an error.

But ecobb, we've been doing this a lot lately, and I love it.. bantering half the day over one thread.. we've been coming up with some cool stuff... bombboy you and me, together we're like ecombbomigit or something...

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Just wondering: When using the hidden fields (as described above), if you go to page 3 and then hit the back button to page 2, does page 2 have page 1's form fields hidden... or if you then forward to page 3, does it have 2's hidden?
 
Yes, so long as you go through the forms, then page 3 has the vars from page 2 and the vars from page 1... page 2 has the vars from page 1.

Its a whole lot easier if you keep the form var names on p2 different from the names on p1.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top