views:

275

answers:

2

Hi,

I am developing a page whereby users can login and demo some pieces of functionality. I only want to allow the user to demo this once per day.

A small example:

I have a web page with 3 buttons (relating to 3 different scenarios). On page load, I look up the database and check if the current logged in user has run any one of the 3 scenarios available (via an audit table). Each button is enabled/disabled based on the results. If any buttons are enabled, then they have not run that demo yet. By clicking the relative button, the demo runs a record is written into the Audit Table, and the button is disabled.

This was working ok, however, I realised that when I refresh the page (and confirm I want to re-submit the information) the demo runs again.

How can I stop this from happening? I need to only allow the user to run the demo once!

Thanks.

A: 

you can check not only on the page load to enable/disable the buttons, but on the button events, you can verify if that task has already been performed

BlackTigerX
+2  A: 

I would suggest that you change your form submission to use the Post/Redirect/Get pattern to avoid a resubmission if they hit refresh on the demo page.

Also, it seems like you should just be able to change the code at the point where it writes the record into the audit table to check to see if the record already exists, and if so, return a different result. I'd be pretty wary about this approach though. The "refresh" functionality of the browser isn't generally something you should be trying to prevent. What happens if a user hits "refresh" in the middle of their demo?

womp
The demo is nothing special it will just send an SMS/Email to the user hence it should happen instantly. I just don't want the user to keep refreshing page and basically spamming themselves with SMS and Emails!
James
Yeah, definitely go with the post/redirect/get pattern then ;)
womp
I will give it a go! Thanks.
James