Forums

add validator for empty fields

Torty 14 Sep, 2009
In CF the "not empty"-validator is implemented. Fields that muss have a value can be validated by this validator.
I miss a validator that validate fields to have to be empty.

Why I miss this?
I have read articles about hidden Spam-Bot protection based on input fields with attractive name i.e. url, email, a.s.o. In the wild (all) bots will fill this field with an url, email address a.s.o. to spread out there "infos".
The idea is now to insert the honeypot field into the form with a small advice like "Leave this field empty." and/or disable this by CSS (i.e. display: none). The user doesn't see the field or see the advice and doesn't fill this field with data. The bot "see" the attractive field and will joyfully put data into it.

The form validation have to validate the honeypot field to be empty. Humans will send the forms and bots will be blocked. Thats the idea - not my, but very interesting. The image captcha isn't accessible for all, but the honeypot field method should work for any people no matter which browser or input device is used.

In CF doesn't exist a validator for field that have to be empty. The only solution is a server side validation script but a default CF-validator looks more professional.

What do you thinking about this option?

Torty
Mizpah 10 Oct, 2009
Hi Torty,

It just so happened that I am testing validation for a project atm🙂

As an experiment I turned off the inbuilt validation, and implemented this code in a form;

[code=php]<span class="syntaxhtml"><br /><span class="syntaxdefault"><?php<br />$doc
GreyHead 11 Oct, 2009
Hi Miz,

That's very neat. And . . . you can use it with the ChronoForms LiveValidation, it seems that this will let you add on extra validations of pretty much any kind.

Here's your code modified a bit (the livevalidation.js is gone as it's using the CF load; the script is wrapped in a domready event and loaded into the page header; I changed the first validation to a US style data validation (because that's what I needed).

All in the Form HTML[code=php]<span class="syntaxhtml"><span class="syntaxdefault"><?php<br />$script  </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">""</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">$script </span><span class="syntaxkeyword">.=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"<br />var sayHello = new LiveValidation('sayHello', { <br />  validMessage: 'Great, that is a date!', <br />  wait: 500<br />});<br />sayHello.add(Validate.Presence, {<br />  failureMessage: 'Gimme a date please !'<br />});<br />sayHello.add(Validate.Format, {<br />  pattern: /(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}/, <br />  failureMessage: 'Gimme a date - like mm/dd/yyyy?' <br />});<br />"</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">$script </span><span class="syntaxkeyword">.=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"<br />var blank = new LiveValidation('blank', { <br />  validMessage: 'This field is now blank', <br />  wait: 500<br />});<br />blank.add( Validate.Format, { <br />  pattern: /^[\s ]*$/, <br />  failureMessage: 'This field is not blank' <br />});<br />"</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">$doc </span><span class="syntaxkeyword">=&</span><span class="syntaxdefault"> JFactory</span><span class="syntaxkeyword">::</span><span class="syntaxdefault">getDocument</span><span class="syntaxkeyword">();<br /></span><span class="syntaxdefault">$script </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"<br />window.addEvent('domready', function() {<br />$script<br />});<br />"</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">$doc</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">addScriptDeclaration</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$script</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">?><br /></span><p>This form is set up to test validations</p><br /><p>Please give
Mizpah 11 Oct, 2009
Thanks Bob,

As mentioned before I need to remember to load stuff via the domready function!!
This topic is locked and no more replies can be posted.