
- MODX 3
- PHP 8.2


Form protection, hiding content from bots, and typical CrawlerDetect usage.
crawlerDetectBlock before validation and send.See crawlerDetectBlock.
Add crawlerDetectBlock to FormIt’s &preHooks. If you have other preHooks, list them comma-separated:
&preHooks=`crawlerDetectBlock,otherHook`'preHooks' => 'crawlerDetectBlock,otherHook'FetchIt processes forms via FormIt on the server. To protect the form:
&preHooks=crawlerDetectBlock``.crawlerdetect_block_message.SendIt uses FormIt; parameters are set in presets (file from si_path_to_presets). To protect the form:
core/components/sendit/presets/sendit.inc.php — it is overwritten on SendIt update).preHooks with crawlerDetectBlock to the needed preset.Preset example:
return [
'contact' => [
'preHooks' => 'crawlerDetectBlock',
'hooks' => 'email,FormItSaveForm',
'validate' => 'name:required,email:email:required',
'emailTo' => 'manager@site.com',
'emailSubject' => 'Contact form',
// ...
],
];If preHooks already exists, add comma-separated: 'preHooks' => 'crawlerDetectBlock,otherHook'.
Snippet isCrawler returns "1" (bot) or "0" (not bot). Call it uncached and use for conditional output.
[[!isCrawler:eq=`0`:then=`[[$chatWidget]]`]]{if $modx->runSnippet('isCrawler', []) == '0'}
{$modx->getChunk('chatWidget')}
{/if}[[!isCrawler:eq=`0`:then=`[[$googleAnalytics]]`]]{if $modx->runSnippet('isCrawler', []) == '0'}
{$modx->getChunk('googleAnalytics')}
{/if}See isCrawler.
Add crawlerDetectBlock to FormIt preHooks. See Quick start.
Use the same preHook for all forms. Add crawlerDetectBlock to &preHooks in each FormIt call.
Run the counter snippet only when the visitor is not a bot:
[[!isCrawler:eq=`0`:then=`[[!yourVisitorCounterSnippet]]`]]{if $modx->runSnippet('isCrawler', []) == '0'}
{$modx->runSnippet('yourVisitorCounterSnippet', [])}
{/if}&preHooks=crawlerDetectBlock``.Exclude bots from product view count:
[[!isCrawler:eq=`0`:then=`[[!msProductViews? &id=`[[*id]]`]]`]]{if $modx->runSnippet('isCrawler', []) == '0'}
{$modx->runSnippet('msProductViews', ['id' => $productId])}
{/if}