In some cases, you won’t have access to server-side code for your forms, and when you need to add a form submitting to an off-site domain you may need anti-spam for sanity’s sake.
Server-side validation is harder to bypass and I don’t recommend using this jQuery-only method if you have access to those better methods.
With that in mind, let’s get started!
This is our basic form shell. Notice that there is no
action for the form to take.
Then, we add a script that:
- Generates a random number
- When form is submitted, tests to see if the user’s input matches the generated number
- If they match, change the form’s
Actionto what it ought to be.
That last step is the key. It means that the form has no valid action until the script gives it one.
This script can be validated server-side as well – just see if the
#verifyNumHidden value matches up with the