Validate Form Field - "is not"

lydianp18 09 Apr, 2013
We're trying to block a bunch of spammers that are submitting forms, they all put the same subject in the subject field of the form "Google". I've been trying to figure out how to validate the field so that the form only goes through if subject is not "Google".. and I can't figure out how to do it. Any hints?

Thanks
Lydia
GreyHead 10 Apr, 2013
Hi Lydia,

Try a Custom Serverside Validation action with code like this in it:
<?php
if ( isset($form->data['subject']) && strpos(strtolower($form->data['subject']), 'google') ) {
  $mainframe =& JFactory::getApplication();
  $mainframe->redirect('http://www.ic3.gov/complaint/default.aspx');
  return false;
} 
?>
!! Not tested and may need debugging !!

This should redirect the spammer away from your site.

Bob
lydianp18 11 Apr, 2013
Thanks, but I've got to be missing something...

I changed it to my field names (ie. company, instead of subject)
<?php
if ( isset($form->data['company']) && strpos(strtolower($form->data['company']), 'google') ) {
  $mainframe =& JFactory::getApplication();
  $mainframe->redirect('http://www.ic3.gov/complaint/default.aspx');
  return false;
} 
?>


and placed the code in the Custom Server Side Validation and put it in the On submit area (I've tried it before and after check captcha), and it's not working.

Did I forget something, or does it need to be in a different spot?
Thanks,
Lydia
GreyHead 18 Apr, 2013
Hi Lydia,

You need to add an Event Loop action into the pink On Fail box of the Custom Serverside validation action, otherwise it does nothing.

Bob
This topic is locked and no more replies can be posted.