Antispam

Antispam

A selection of useful snippets from various authors for quick website development on ModX Revolution.

1. antispam — snippet that checks form content for signs of spam

<?php $success=true; $haserror=false; $forb=array( '@', 'http', 'https', '://', 'www' ); foreach ($forb as $f){ if($haserror==false){ $haserror=strpos($value,$f); } } /*Перевірка телефону (якщо не потрібна, закоментуйте рядки 19-21)*/ if(substr_count($key,'phone')>0){ if($value!='' and strlen($value)<16){$haserror=1;} } if ($haserror!=false) { $validator->addError($key,'Неприпустиме значення!'); $success=false; } return $success;

 

2. checkSpamTime

<?php if (count($_POST)) { $flag = false; $now = microtime(true); if ((isset($_SESSION['now'])) && (($now — $_SESSION['now']) > 2)) { $flag = true; } return $flag; } else { $_SESSION['now'] = microtime(true); }

 

3. validate

<?php function text_error(){ return false; die(); } if(isset($_POST['org'])){ if($hook->getValue('org')!=''){ text_error(); }else{ return true; } }else{ text_error(); }
if ($(".form").length > 0) { $(".form").append( '<input type="text" name="org" value="" class="org" style="visibility:hidden; height: 0; width: 0; padding: 0; border:none;"/>' ); } 
Fill out the brief and get an approximate development cost
Website Brief Logo brief Print brief