
Integration
Form protection, hiding content from bots, and typical CrawlerDetect usage.
Form spam protection
How it works
- User submits the form.
- FormIt runs preHook
crawlerDetectBlockbefore validation and send. - If User-Agent is a bot → form is not processed; message from settings is shown.
- If human → form is processed as usual.
See crawlerDetectBlock.
Regular form (FormIt)
Add crawlerDetectBlock to FormIt’s &preHooks. If you have other preHooks, list them comma-separated:
&preHooks=`crawlerDetectBlock,otherHook`'preHooks' => 'crawlerDetectBlock,otherHook'AJAX form (FetchIt)
FetchIt processes forms via FormIt on the server. To protect the form:
- In FetchIt config set the URL/page where FormIt is called.
- In that page’s FormIt call add
&preHooks=crawlerDetectBlock``. - When a bot is blocked FetchIt gets an error response and shows the message from
crawlerdetect_block_message.
AJAX form (SendIt)
SendIt uses FormIt; parameters are set in presets (file from si_path_to_presets). To protect the form:
- Open your presets file (your copy, not the default
core/components/sendit/presets/sendit.inc.php— it is overwritten on SendIt update). - Add
preHookswithcrawlerDetectBlockto the needed preset. - When a bot is blocked SendIt returns an error and shows the message from CrawlerDetect settings.
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'.
Hiding content from bots
Snippet isCrawler returns "1" (bot) or "0" (not bot). Call it uncached and use for conditional output.
Widget for humans only
[[!isCrawler:eq=`0`:then=`[[$chatWidget]]`]]{if $modx->runSnippet('isCrawler', []) == '0'}
{$modx->getChunk('chatWidget')}
{/if}Analytics for humans only
[[!isCrawler:eq=`0`:then=`[[$googleAnalytics]]`]]{if $modx->runSnippet('isCrawler', []) == '0'}
{$modx->getChunk('googleAnalytics')}
{/if}See isCrawler.
Typical scenarios
Contact form
Add crawlerDetectBlock to FormIt preHooks. See Quick start.
Multiple forms on the site
Use the same preHook for all forms. Add crawlerDetectBlock to &preHooks in each FormIt call.
“N users online” counter
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}“Request a call” form (FetchIt)
- Ensure FetchIt is configured to call FormIt on the server.
- In FormIt on the target page add
&preHooks=crawlerDetectBlock``. - When a bot is blocked FetchIt shows the message from CrawlerDetect settings.
E‑commerce — “Viewing this product”
Exclude bots from product view count:
[[!isCrawler:eq=`0`:then=`[[!msProductViews? &id=`[[*id]]`]]`]]{if $modx->runSnippet('isCrawler', []) == '0'}
{$modx->runSnippet('msProductViews', ['id' => $productId])}
{/if}