Log in

No account? Create an account

Disable third party JS form submission - Look, someone's on that tree

Mar. 13th, 2011

04:29 pm - Disable third party JS form submission

Previous Entry Share Next Entry

Let's say you have a very nice form on your page and you dislike people who write user script. Scripts that mess up with your form for example.
Typical form submission with user script would be:

Very well, lets prevent this! Each form has a submit button, lets add one that has type submit, but in addition has the name 'submit' too (you should know to ignore its value on your server side logic):
<button type='submit' value='whatever' name='submit'>My button</button>
Now we have harder to spot intuitive way to submit the form with javascript, $('myform').submit() will give TypeError as the 'submit' property of the HTMLFormElement is no longer a function, instead it is an HTMLButtonElement.

This little trick of course is easy to catch and overcome, however it is very easy to implement and will stop the less educated scriptwriters from messing up with your manual form submission requirement.

Current Location: Bulgaria, Varna