How to prevent spam through your website forms

We all hate spam in our email inbox, but we rarely try to get to the root cause and purpose of spam. Many webmasters face the problem of receiving spam emails through their website forms. These are usually contact forms that are set up for visitors to post their queries or give feedback. Spammers try to hijack these forms to send spam, either by manipulating where the forms send emails or by flooding the webmaster with spam. This article points out some of the ways you can combat spam on website forms intended for feedback, comments, inquiries, and any other contact.

Form Field Validation

A very important part of having a secure form is making sure there is strict validation of the form fields. This is best explained with an example. When you accept a phone number through the contact form, you can code the form to ensure that only numbers are entered into the form field. Similarly, for an email address field, the form must be able to determine that a well-formed email address was entered. If the fields contain something that field is not supposed to contain, like special characters or some fun text, then the form will throw an error and won’t submit until the errors are fixed. This prevents any malicious code or text from being inserted into the form. It also prevents automated bots from filling out the form without understanding what is required and how it should be filled out.


One of the most effective ways to combat spam is to enable a captcha at the end of each form. The captcha requires the user to enter a verification word or number that is displayed on an image. This prevents bots and automated systems from mindlessly submitting forms. Since bots usually can’t detect text within images, they don’t enter the correct Captcha text, which prevents the form from submitting.

confirmation alert

Another simple trick that can be used to harass spammers is to add a confirmation alert box that pops up to confirm the details the user is trying to submit. Robots and automatic form submission software cannot click the confirmation button in the alert box. Something like “Are you sure you want to submit the form? Yes No” can be an extra layer of protection against comment spammers. This is also a good way to allow users to review the information they submit and correct any errors or typos before submitting the form.

anti-spam plugins

Akismet is an anti-spam plugin used for WordPress, which can identify genuine comments and filter spam comments. This can be useful if you don’t want to enable a captcha confirmation box or can’t have specific validation on your form. Similar anti-spam plugins are also available for other platforms. While Akismet-type plugins are not 100% correct and may generate some false positives, they do a very good job of filtering out noise.

registration information

One of the most important things a developer can do to track spam sources and spam patterns is to record additional user information. This means that along with the normal fields that the user submits, the form will also capture their IP address, machine name, browser details, location information, and similar information that can be used to trace the source of the spam. With this information, you can take action against the spammer or even block your IP address. This way, they won’t be able to keep harassing you or making random deliveries.

Some programmers also rely on hidden form fields in CSS, which prevent bots from seeing the names of form fields, preventing them from knowing what data to autofill in text boxes. Consult your coder for the best solution for your website.

Comments |0|

Legend *) Required fields are marked
**) You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Category: Technology