I have two custom snippet/functions for my contact form, so my snippet call looks like this:
[!getServer!]
[!checkField!]
[!eForm? &formid=`ContactForm` &tpl=`ContactForm` &report=`ContactReport` &to=`[email protected]` &subject=`sottwell.com Contact` &thankyou=`ThankYou` &from=`[+email+]` &fromname=`[+name+]` &replyto=`email` &eformOnBeforeMailSent=`getServer` &eformOnValidate=`checkField`!]
The checkField snippet looks like this:
<?php
function checkField(&$fields,&$vMsg,&$rMsg) {
if(!empty($fields['Last__Name'])) {
return false;
} else {
return true;
}
}
?>
The bogus field is moved off the screen in the CSS file:
#contactArea #LastName{position:absolute;text-decoration:underline;background-color:#CC0000;left:0px;top:-500px;width:1px;height:1px;overflow:hidden;}
You can see the form if you view source on my site (
http://sottwell.com); even though I’m using a silly jQuery popup for my contact form, I haven’t implemented the AJAX version yet so you can see the form in the source.
I have a sneaking suspicion that I should be able to use eForm’s custom validation in the form field’s eform attribute to check that it’s empty, but I really hate regular expressions.