
- MODX 3
- PHP 8.2


crawlerDetectBlock before validation and send.isCrawler treats the request as a bot (JayBizzle headers, not User-Agent alone), the form is not processed. The message from settings is shown.PHP service: $modx->services->get('CrawlerDetect\\CrawlerDetectService'). Methods: isCrawler($ua = null) and getMatches(). Missing vendor class: method returns false with no log line.
Add crawlerDetectBlock to FormIt’s &preHooks. List other preHooks comma-separated.
&preHooks=`crawlerDetectBlock,otherHook`'preHooks' => 'crawlerDetectBlock,otherHook'FetchIt processes forms via FormIt on the server.
&preHooks=`crawlerDetectBlock`.crawlerdetect_block_message.SendIt uses FormIt. Parameters are set in presets (file from si_path_to_presets).
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.
[[!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}Add crawlerDetectBlock to FormIt preHooks. See Quick start.
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}Same steps as AJAX form (FetchIt).
Exclude bots from product view count:
[[!isCrawler:eq=`0`:then=`[[!msProductViews? &id=`[[*id]]`]]`]]{if $modx->runSnippet('isCrawler', []) == '0'}
{$modx->runSnippet('msProductViews', ['id' => $productId])}
{/if}