EOG
EOG

Reputation: 1757

Prevent from multiple form submitions without javascript

I've got an Asp.net MVC action that creates user account(after input validation). And a View containing registration form that invokes this action. While action validates input, user is left with webbrowser waiting for server response and click submit button a few more times. This creates several accounts. Is there a way to prvent user from form resubmition without javascript. I cannot use javascript in this project it is intended for non javascript browsers. Or can you suggest(server) other solution?

EDIT:

  1. This form request use POST method
  2. JavaScript is not allowed because this Web Application is aimed for special web browsers for people with disabilities that do not support javascript

Upvotes: 1

Views: 278

Answers (3)

Daniel Uribe
Daniel Uribe

Reputation: 778

Is it a requirement to use MVC? I think you can accomplish something similar using WebForms. When the user submit the request, in the code behind you can disabled the submit button like this:

btnSubmit.Enabled = false;

But if MVC is a must be, @walther answer would be correct

Upvotes: 0

Kami
Kami

Reputation: 19447

You can add a unique hidden token as part of the form. This token can also be saved as part of the session on the server.

When the user posts the form on the first action, the token is validated and a flag set to indicate the request is being processed. The action processed and results presented. If, while awaiting results, the user attempts to repost the request, the token validation fails as the request is still being processed.

On a side node, the main reason people continuously click is that there is no feed back on whether the request was received by the server or not. To this affect, it might be better to redirect the user to an interim page that shows the request is being processed. Which in conjunction with the above can be used to show the request progress and redirect to the appropriate page when completed.

Of-course, you should also consider making the process a bit lighter. So, that the system can respond quickly to input rather than making the user wait.

Upvotes: 0

walther
walther

Reputation: 13600

You have to handle the situation on the server-side then, there's no way around that.

There are 3 options that come to my mind atm:

  • create a cookie and for each submit check if it exists
  • similar, but using a session object
  • before creating a new account, always check if the user exists in the database. THIS should be a no-brainer anyway!

Upvotes: 1

Related Questions