Reputation: 6365
I have quite a few forms on my site that are submitted using jQuery ajax. When I recently disabled JavaScript to do a bit of testing, I noticed these form submit the usual way.
Is there anything that can be done to prevent them from being submitted at all when javascript is not available or disabled?
My forms do not have a method
or action
. These are specified in ajax itself. I use a button
instead of
Anything I can do to stop them from being submitted?
I know I can generate/enable buttons and things after the page loads, but what if a user were to deliberately disable JavaScript after the page loaded?
Upvotes: 0
Views: 88
Reputation: 701
my suggestion is to handle bad form posts in the server side logic. This form must be going somewhere right. then if user has js disabled, there is still validity checks, preventing junk from hitting the server. Ultimately, the user has a choice to enable or disable it. This will prevent bots, and other spam from hitting the server's database for example.
Upvotes: 1
Reputation: 344
If you make your submit buttons a div, a or anything other than a tag it will not post using the form wrapper. this allows for a form of graceful degradation based on your needs. when not using the the form doesn't act unless the JavaScript is enabled and listening. using the a tag in a situation like this would allow you to still submit if you wanted but via the ahref attribute and not the form action. also the Internet Explorers might behave differently so keep an eye out and test thoroughly.
see also: When To Use The Button Element http://css-tricks.com/use-button-element/
Upvotes: 1