Foundation Abide Customer Validator Spam Protection

94 Views Asked by At

Is it possible to use Foundation's Abide Validation as a spam preventative? I'd like to ask a simple question at the end of my form, i.e. 'What is 2+2?'. The answer must be 4 to submit the form.

Something like this:

<form data-abide>
  <div class="row">
    <div class="small-12 column">
      <input type="text" placeholder="what is 2 + 2?" required>
      <small class="error">You're not very good at math, are you?</small>
    </div>
  </div>
</form>

1

There are 1 best solutions below

0
user3830562 On

Yes, I had implemented what you described in a previous project, and it worked as a spam deterrent.

You first need to create a JS function to handle your question by adding it as a custom validator to Abide. This may work for your 2+2 question. Add the following to the bottom of your HTML file:

$(document).foundation({
    abide : {
        validators: {
            mathCheck: function(el, required, parent) {
                return el.value == 4;
            }
        }
    }
});

Also, you now have to add the validator as an attribute:

<input type="text" placeholder="what is 2 + 2?" data-abide-validator="mathCheck" required>

That should work. Good luck.