【问题标题】:Typo3 9.5 prefill form field with get parameterTypo3 9.5 使用 get 参数预填充表单字段
【发布时间】:2019-11-24 20:39:52
【问题描述】:

我使用 TYPO3 系统扩展“表单”并希望使用 GET 参数预填充输入字段。

这个TYPO3 8.7. Form prefill input field 正在工作,但只有 no_cache=1。是否有另一种不停用整个缓存的解决方案?

谢谢 大卫

【问题讨论】:

    标签: forms typo3


    【解决方案1】:

    是的,您可以,但您需要创建 HOOK

    这在documentation中有描述

    例如,HOOK

    /**
     * @param \TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface $renderable
     * @return void
     */
    public function initializeFormElement(\TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface $renderable)
    {
        if ($renderable->getUniqueIdentifier() === 'contactForm-text-1') {
            $renderable->setDefaultValue('foo');
        }
    }
    

    还有连接钩子

    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'][<useATimestampAsKeyPlease>]
        = \VENDOR\YourNamespace\YourClass::class;
    

    请阅读“表单框架”的文档。

    我做到了,得到了我需要的结果。

    【讨论】:

    • 感谢您的注意,但这并不能解决缓存问题。如何将表单设置为 nocache 以预填充字段,而不停用完整的缓存?
    【解决方案2】:

    您可以禁用表单页面内容列的缓存,例如:

    lib.content = COA
    lib.content{
        10 < styles.content.get
    }
    [page["uid"] == 512]
        lib.content = COA_INT
    [global]
    

    【讨论】:

    • 在页面条件中使用config.no_cache = 1禁用单个页面的缓存不是更容易吗?
    • 这也是可能的,但明确要求提供替代解决方案。从性能的角度来看,考虑到 indexed_search 的可能使用,如果页面的剩余部分被缓存也更好。
    【解决方案3】:

    感谢 TYPO3UA 的回答。但是你应该使用钩子'afterBuildingFinished',因为'initializeFormElement'钩子是在表单定义的属性设置在表单元素中之前执行的。因此,表单定义中的默认值(即使它是一个空字符串)将覆盖在 initializeFormElement' 挂钩中设置的值。 见:https://forge.typo3.org/issues/82615

    所以这适用于设置表单元素的默认值:

    /**
    * @param \TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface $renderable
    * @return void
    */
    public function afterBuildingFinished(\TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface $renderable)
    {        
            if (method_exists($renderable, 'getUniqueIdentifier') && $renderable->getUniqueIdentifier() === 'contactForm-text-1') {
                $renderable->setDefaultValue('Value');
            }
    }
    
    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['afterBuildingFinished'][<useATimestampAsKeyPlease>]
        = \VENDOR\YourNamespace\YourClass::class;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-06
      • 2011-07-22
      • 1970-01-01
      • 2018-12-15
      相关资源
      最近更新 更多