Jump to main content Jump to doc navigation

Using a Blank No-Spam Field

Often, spambots fill every form field to pass validation. Thus, a good way to prevent spam is to add a field in your form and require it to be blank for submission to succeed.

FormIt provides you with the "blank" validator, which can be used to achieve a "nospam" field.

Setup

Simply add the following input into your form. You can change the name of the field at any time; using commonly used field names like "workemail" can be used to trick spambots into filling in the field:

<input type="hidden" name="workemail" value="" />

Then, in your FormIt call, add the blank validation:

[[!FormIt? &validate=`workemail:blank`]]

If you wish to provide an error message to be displayed, you can do so in the normal FormIt syntax (this example would be [[+fi.error.workemail]]).

Make sure not to use an existing field name in your form for the nospam field! This will prevent FormIt from processing your form.

See Also

  1. FormIt.Examples.Custom Hook
  2. FormIt.Examples.Simple Contact Page
  3. FormIt.Handling Selects, Checkboxes and Radios
  4. FormIt.Using a Blank NoSpam Field

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • CrewMark
  • Chris Fickling
  • deJaya
  • Lefthandmedia
  • Murray Wood
  • eydolan
  • Following Sea
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

$301 per month—let's make that $500!

Learn more