
1C: Bitrix, protection of arbitrary forms from spam
CleanTalk 1C: Bitrix Antispam module without CAPTCHA allows, in addition to protecting the described forms, it is easy to make any form of protection. The module’s methods were written specifically for the possible expansion of functionality. Here I give an example of how to do this.
Suppose you want to check for spam forms with the following fields:
email, nickname, title and message.
All that is needed is to put the code for calling the CleantalkAntispam :: CheckAllBefore method with the necessary parameters in /bitrix/php_interface/init.php .
/bitrix/php_interface/init.php
Actually, the code is very simple: collecting parameters from the form, calling validation, analyzing the result. It is in this way that all the methods of the module for checking forms are made. If you need to add protection for the next form that customers need, we simply add a method similar to the one given. You can verify this by looking at the module code itself.
The parameter $ WEB_FORM_ID is not checked, its check can be added if necessary.
I note that when checking inside the CleantalkAntispam :: CheckAllBefore () function, a JavaScript test is used. The test code is automatically installed on the site pages when the module is turned on (including in the module settings), and call CleantalkAntispam :: CheckAllBefore ()it is also necessary when the module is on, otherwise the JavaScript test will fail.
I also note that the response flag $ aResult ['stop_queue'] is not analyzed here . This flag indicates explicit spam and is used, for example, in approving comments: if it is set, then the comment is rejected, if reset, then it is sent for manual moderation. You can easily add such a check yourself. Details on the CleanTalk API are here .
Suppose you want to check for spam forms with the following fields:
email, nickname, title and message.
All that is needed is to put the code for calling the CleantalkAntispam :: CheckAllBefore method with the necessary parameters in /bitrix/php_interface/init.php .
/bitrix/php_interface/init.php
]*>/iu', '', $err_str);
} else {
$err_str=preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/i','',$aResult['ct_result_comment']);
$err_str=preg_replace('/<[^<>]*>/i', '', $err_str);
}
$APPLICATION->ThrowException($err_str);
return false;
}
}
}
}
}
?>
Actually, the code is very simple: collecting parameters from the form, calling validation, analyzing the result. It is in this way that all the methods of the module for checking forms are made. If you need to add protection for the next form that customers need, we simply add a method similar to the one given. You can verify this by looking at the module code itself.
The parameter $ WEB_FORM_ID is not checked, its check can be added if necessary.
I note that when checking inside the CleantalkAntispam :: CheckAllBefore () function, a JavaScript test is used. The test code is automatically installed on the site pages when the module is turned on (including in the module settings), and call CleantalkAntispam :: CheckAllBefore ()it is also necessary when the module is on, otherwise the JavaScript test will fail.
I also note that the response flag $ aResult ['stop_queue'] is not analyzed here . This flag indicates explicit spam and is used, for example, in approving comments: if it is set, then the comment is rejected, if reset, then it is sent for manual moderation. You can easily add such a check yourself. Details on the CleanTalk API are here .