-
☆ A M B ☆
- 24,524 Posts
Use one of eForm’s event traps and write a snippet with a function containing your code. Here’s the snippet I use to check on a "hidden" form field
function checkField(&$fields,&$vMsg,&$rMsg) {
if(!empty($fields['Last__Name'])) {
return false;
} else {
return true;
}
}
I added &eformOnValidate=`checkField` to my eForm snippet call. The snippet with your custom function has to be called
before the eForm call, in order to make the function available to the eForm code when it runs.
See the eForm documentation in the docs directory that comes with eForm for more on how to write event plugins for eForm.
Thanks ,
I found few functions like this, but I’m trying to understand how to put the random numbers on the form and then check against POST[hidden field] with the function..
If you can translate my initial script into a modX format: like form is like this and check against POST[sum] etc..would be much appreciated.
Not php expert, and don’t understand much modX that’s why I’m asking for step by step..
thanks
hmm. I’ve now made a custom validation function, which seems to work (somewhat); i.e. using a legal input = form is sent. Incorrect value = blank screen.
Is this "expected behaviour"? What do I need to do in order to display a custom error msg, or simply just display the form again with the erroneous input field marked via CSS? Just a blank page is not ideal :|
Show us what you’ve done... i.e. formTemplate, snippet call(s) and function(s).
I find it rather difficult to assist without this.
@Susan
Your idea with the hidden field sounds great, I don’t like captchas very much and so I’m looking for a better solution, could be that I found one, thanks to your post above...
I just have one question...how has this hidden field to look like? Must it be hidden or must it be text like:
<div class="input hidden">
<input type="text" name="diespammer" />
</div>
so the css-class "hidden" makes the input display: none, so it isn’t visible for the normal user but a bot would fill it out?? Can a type="hidden" field be filled out?? I also don’t want to give the input an ID because I have sometimes more than one form on a page, is this a problem? I thing the input names are used, but I’m not sure...
So I would do it like you proposed:
Snipppet [[eForm_dieSpammer]]:
function dieSpammer(&$fields,&$vMsg,&$rMsg) {
if(!empty($fields[’diespammer’])) {
return false;
} else {
return true;
}
}
Call on in the modX document:
[[eForm_dieSpammer]]
[[eForm? ... &eFormOnValidate=`dieSpammer` ... ]]
(have to make the snippet calls uncached because I use Ditte all over the place =D)...
thanks for your reply!