Differences between revisions 1 and 2
Revision 1 as of 2005-01-21 03:04:33
Size: 1741
Editor: CPE-61-9-201-26
Comment: Migrated page.
Revision 2 as of 2009-09-20 22:00:13
Size: 1741
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

Turbine 2.x User's Guide: Preventing Double Submit of Forms

In your TurbineResources.properties you define a session validator that is processed before your action is. This allows you to force only logged in users to be able to execute a session, or do things like preventing double submission of forms.

Look for:  action.sessionvalidator=sessionvalidator.TemplateSessionValidator 

There are others as well, including a TemplateSecureSessionValidator. You can create your own by just subclassing SessionValidator and updating your TurbineResources.properties file.

To prevent the double submission of forms, you must put into form a hidden field like this:  <input type="hidden" name="_session_access_counter" value="$data.getUser().getTemp("_session_access_counter")"/> 

This will allow the TemplateSessionValidator to check the current session_access_counter with the one stored in the user object. If it hasn't incremented, then the user has hit the back button or refresh button.

You must specify where to send the user if an invalid state happens. You can specify either a template or a screen, but if you specify both then only the template will be used (along with the appropriate screen class according to the normal screen loader algorithm):  template.invalidstate=InvalidState.vm  or  screen.invalidstate=error.InvalidState 

On this page you can put an error message allowing the user to recover from hitting the wrong button. Look at the class org.apache.turbine.modules.screens.error.InvalidState to see a more complex example that allows the user to undo their mistake.

-- EricPugh

Turbine2/UsersGuide/TurbineActionDoubleSubmit (last edited 2009-09-20 22:00:13 by localhost)