Guarantee JavaScript for Forms
Tech-oriented websites like Willmaster.com attract technically oriented folks. Some, perhaps many, arrive with their browser's JavaScript turned off.
Which is fine. Except when it's not.
An example of when it's not fine is when a form requires JavaScript to perform correctly.
There are many reasons forms may require JavaScript. Examples are to insert/
The most imperative reason to require JavaScript, at least for Willmaster.com, is to block unwanted form submissions and reduce form spam. Without JavaScript, a form will either not submit or fail silently.
When a form is there and the person finds they can't use it or it won't submit, it can be frustrating.
To eliminate the frustration, or most of it, a noscript
tag can be inserted near the top of the form, or near the submit button, with the message that JavaScript is required to use the form. Here is an example.
<noscript> <h4>Note: JavaScript is required to make this form fully functional.</h4> </noscript>
But that doesn't guarantee JavaScript will be available for the form. Further, the message might not be seen or the form just abandoned.
A way to guarantee JavaScript will be available when someone uses your form is to deliver it with JavaScript. Without JavaScript, the form never becomes available to be used.
There are various ways to deliver forms to a web page with JavaScript. Any of them will ensure the browser can run JavaScript before the form is made available.
Here are three ways:
-
Insert the form with a regular JavaScript tag.
-
Publish the form with Ajax.
-
Use a Spam-free form.
Here are descriptions of the three methods:
Insert the form with a regular JavaScript tag.
With this method, you convert your form to JavaScript, store the JavaScript in a file on your server, and insert the form into your web page with a JavaScript tag.
-
Use the Text to JavaScript Converter to convert your form source code into JavaScript.
-
Save the JavaScript as
myform.js
or other.*js
file name that you prefer. Upload it to your server and make a note of its URL. -
In the source code of the web page where the form is to be delivered, insert:
<script src="http://example.com/myform.js>" type="text/javascript"></script>
Replace
https://example.com/myform.js
with the URL to the JavaScript you uploaded to your server in the previous step.
The form will be delivered to your web page only for browsers that run JavaScript.
Publish the form with Ajax.
This method does not slow the web page load in order to insert the form. With Ajax, the form is published when the browser gets around to it.
There are a number of ways to do this, but all are basically the same: The Ajax obtains the form source code from the server. Then it publishes the source code into a specific div.
The Ajax Form System article contains a how-to for one method. Using the system will display your form on your web page with Ajax.
Use a Spam-free form.
A spam-free form as obtained from SpamFreeForm.com not only ensures the browser has JavaScript enabled, it is highly effective at blocking spam.
While I can never guarantee this, because spammers get ever more creative, I believe spam-free form completely blocks all automated spam.
The service has been in operation for some years. There has been no confirmed instance of a form-spamming bot successfully using the form. And the form still remains easy to use — without requiring people to proactively prove they are human.
The service is free.
A Good Reason
A good reason for providing forms only to browsers with JavaScript enabled, in addition to ensuring the browser's JavaScript is actually turned on, is form spam prevention.
As mentioned, the spam-free form is highly effective at blocking automated form spamming. The other two methods also are fairly good at that because most form spamming bots (so far) don't compile and run JavaScript.
(This article first appeared with an issue of the Possibilities newsletter.)
Will Bontrager