CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Browser Back-button

Print topic Send  topic

Author Message
materix

Posts: 161
Posted: 06/15/2008, 5:05 AM

Hi.

Sometimes my users press the back-button in the browser after submitting a new record, because they want to change a value of a submitted field. This causes problems, because when they press submit for the second time, then they get a primary-key violation (which is good, by the way).

Is there any method to ensure that the record changes to EditMode, when users use the browser back-button?


NB: "Users! Can't live with them. Can't live without them..."
View profile  Send private message
materix

Posts: 161
Posted: 06/17/2008, 12:27 AM

Any hint on this would be greatly appreciated.
View profile  Send private message
mentecky

Posts: 321
Posted: 06/17/2008, 11:21 AM

materix,

You almost stumped me on this one... and I hate being stumped. :-D

There really seems to be no easy way to pull this off... but here is how I hacked it and it seems to work fine.

In my record, I added a hidden field named form_submitted and set it for integer, default value of 0.

Next I selected my record control and in Events - Client - On Submit I added the following code:

    document.forms["personal_message"].form_submitted.value = 1;  

In this example my form/record is named personal_message. Change the code to reflect your form name.

Next, I selected my record control and in Events - Client - On Load I added the following code:

   if (document.forms["personal_message"].form_submitted.value == 1)  
   {  
      location.replace('personal_msg_list.php');  
   }  

Replace 'personal_msg_list.php' with the page you want the user to be sent to if they hit BACK.

So far this looks great, but if there is an error on the submitted form, the user won't get a chance to edit it. So, we need to select our record control once again. In the On Validate Server event add the following code:

   if ($personal_message->CheckErrors())  
   {  
      $personal_message->form_submitted->SetValue(0);  
   }  

This code resets the hidden value to 0 if there are any errors and we expect to be going back to the same page.

That's all there is. I hope that helps.

Rick

_________________
http://www.ccselite.com
View profile  Send private message
wkempees


Posts: 1679
Posted: 06/17/2008, 1:38 PM

It had me stumped too, Rick, especially as the post is meant to allow Back Button to pickup a previously InsertMode Form and force it into EditMode.
I beleive that your method of redirectinfg a form reached by pressing BackButton is better than trying to force editmode.
If the form is on an autonumkey table, it would in fact keep on adding records!

Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
mentecky

Posts: 321
Posted: 06/17/2008, 1:53 PM

Thanks Walter,

Not a perfect solution, but it seems to work. I don't see any way to switch to edit mode with the exception of a bunch of code in Before Insert, that would be really problematic.

Rick
_________________
http://www.ccselite.com
View profile  Send private message
wkempees


Posts: 1679
Posted: 06/17/2008, 2:04 PM

Rick,
Dont even try to do this, it is fundamentally wrong.
In a datacentric application one would always want to restrict the use of previously (cached) pagesas a means of editing data.
If this is intended than consider this:
fase1: Blank form is entered, InsertMode, user enters data and presses submit.
Either autonumkey or defined key, (get the keyvalue, redirect to current form, adding the keyvalue to the URL.
Fase2, Form (filled) is shown again, user can edit or press Cancel.
Fase 3 back to situ before Fase1.
All cached pages should show 'expired' message and/or redirect to an errorpage (your method for instance).

Walter

_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
mentecky

Posts: 321
Posted: 06/17/2008, 2:39 PM

Walter,

Yeah but IE sucks at honoring expired and non-cached pages. I've tried it all. This with the proper headers would at least cover the times IE refuses to listen to the developer. 8-)

Rick
_________________
http://www.ccselite.com
View profile  Send private message
materix

Posts: 161
Posted: 06/17/2008, 3:00 PM

Hi Rick.

Thanks a lot for help. It works! :-)
View profile  Send private message
mentecky

Posts: 321
Posted: 06/17/2008, 3:01 PM

Quote materix:
Hi Rick.

Thanks a lot for help. It works! :-)

Most excellent!

Glad we could help!

Rick

_________________
http://www.ccselite.com
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.