Jump to content

how to get around a client resubmitting/leaving the form handler whilst processing


Greywacke
 Share

Recommended Posts

hi all,i was wondering if it is at all possible, to prevent a user from leaving a form handler during processing, as this is an important part, quite like processing a credit card...this form can take up to 1-3 minutes to process, depending on the amount of suppliers matched.i've tried to do this by adding the following before the php code of the handler:

<div id="progressbg" style="visibility: visible;">	<div id="progressloader"> </div></div><script language="javascript">window.onload = function () {	var lyr = document.getElementById("progressbg");	lyr.style.visibility = "hidden";}window.onbeforeunload = function (e) {	var e = e || window.event;	var lyr = document.getElementById("progressbg");	if (lyr.style.visibility == "visible") {		// For IE and Firefox		if (e) e.returnValue = "Please be patient while we process your request.";		return "Please be patient while we process your request.";	}}</script><style type="text/css">div#progressbg {	position: fixed;	z-index: 100;	top: 0;	left: 0;	width: 100%;	height: 100%;	border: none;	background: transparent url("progress-bg.png") top left fixed repeat;	text-align: center;	vertical-align: middle;}div#progressloader {	position: fixed;	z-index: 101;	width: 128px;	height: 47px;	border: none;	left: 45%;	top: 45%;	background: transparent url("progress-sp.gif") top left scroll no-repeat;	text-align: center;	vertical-align: middle;}</style>

but if the user tries to leave the handler whilst processing - such as refreshing it (thus resubmitting it) or pressing stop or back, it gives him/her the option of cancelling the page. this tends to mess up the database selections and insertions, especially if there are more than one instance of the form being handled on the server. what to do? i have no idea how this could be fixed on the handler itsself.i guess with a compiled and signed javascript one might be able to do this, but something tells me that was only for netscape back in the day...if i add an alert in while the page is loading, then the onunload cancelling query still pops up regardless with the choice of leaving the page while loading.

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

Well, you can't really "force" a person to stay on the page (or else every dodgy marketing site would do it!).Why not just run the script internally on the server, instead of serving it to the user?

Link to comment
Share on other sites

okay that would be php, like i said - i don't know how to lol... :)and what is there to make sure that the user stays with the handler while its being processed, even if it takes up to a minute or three? this is the reason why i try to keep the user on the page while processing the submitted form.why i asked if a signed script would work, was because the dodgy marketing sites out there wouldn't easily get a trusted certificate.

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

Signed script or not, you're asking permission to hijack a browser. It's not going to happen. The client owns the computer and the software. That gives the client certain prerogatives. Canceling operations and navigating to other pages are included in those prerogatives.

Link to comment
Share on other sites

hi again,i've decided to add them as displayed in the following preview pages:CanopyXchange.za.net Processing CaptureSalesPages (QuoteMe.za.net) Processing Capturethe onload event has been commented to display the div that acts as a "film" to deter people from leaving the page before fully processed.the alert has been dropped, rather displaying the reason why leaving would not be a good idea.ISSUE RESOLVED! :)

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

Comment: you can always use SQL transactions or similar so that your database isn't messed up if the process is interrupted halfway.

Link to comment
Share on other sites

For what it's worth, I've got a pretty large application that some of our customers have a lot of data in, and that thing has a couple tools that require several minutes to finish on some of the larger installations. I've found that I can start the tool, see the 5 minute PHP timeout expire, and see the ajax request fail with a 500 error, but I can verify through phpMyAdmin that the queries continue to run until the process finishes.I'm actually not quite sure that I understand that though, because the queries run in a loop in PHP and PHP obviously exits. It might be that PHP sends all of the queries as soon as it can and MySQL will batch them and run them until the batch is empty.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...