undkonsorten / typo3-extbase-honeypot
extbase对象表单的蜜罐元素
1.0.0
2023-12-07 13:47 UTC
Requires
- typo3/cms-core: ^9.5 || ^10.4 || ^11.5 || ^12.4
README
它做什么?
此扩展允许您向extbase扩展添加一个简单的蜜罐字段。它可以减少特定表单的垃圾邮件,但无法排除所有机器人。
安装
只需通过composer要求
composer require undkonsorten/typo3-extbase-honeypot
激活此扩展以支持TYPO3版本11之前的版本。
用法
控制器
在控制器中注入 \Undkonsorten\HoneyPot\Service\HoneyPotService
,例如 $honeyPotService
。
然后在接收要保护的表单的操作之前调用它
public function initializeCreateAction(): void { $this->honeyPotService->configureHoneyPotForArgument($this->arguments->getArgument('dto'), $this->request->getArgument('dto'), '_hp'); } public function createAction(DTO $dto): ResponseInterface
其中 createAction
是适当的形式操作,dto
是您的参数名称,_hp
是您的蜜罐字段的虚拟属性名称。只需确保避免与现有属性冲突。
模板
现在将字段添加到模板中,如下所示
<f:render partial="Field/HoneyPot" section="Main" arguments="{field:'_hp'}" />
其中 _hp
是您在控制器中选择的名称。现在剩下的工作是为您的视图配置正确的部分位置,例如通过 TypoScript
plugin.tx_myext {
view.partialRootPaths.42 = EXT:extbase_honeypot/Resources/Private/Partials/
}
如果要显示字段被填写的错误消息,您可以使用locallang文件中的示例: typo3-extbase-honeypot/Resources/Private/Language/locallang.xlf
将带有正确错误码的行复制到您的扩展/站点包/ wherever,并根据需要更改属性名称,如果您不使用默认的 _hp
。
将f:translate片段添加到使用的操作模板中。
<f:if condition="{validationResults.flattenedErrors}"> <ul class="formerror"> <f:for each="{validationResults.flattenedErrors}" key="propertyPath" as="errors"> <f:for each="{errors}" as="error"><li> <f:translate key="error.{error.code}.{propertyPath}" arguments="{0:propertyPath}" /> </li></f:for> </f:for> </ul> </f:if>
配置
无需进一步配置 - 现在您需要的一切都在您的代码中。当然,您可以像字段名称一样进行配置。