【问题标题】:Using dynamic "non Domain" Arguments in Typo3 Extbase Controller在 Typo3 Extbase 控制器中使用动态“非域”参数
【发布时间】:2015-08-03 08:24:48
【问题描述】:

由 JavaScript 添加到 Fluid-Form 的 Form-Elements 不会作为参数传递。

  • 如何正确操作?
  • 如何使用 JavaScript 动态添加表单域?

预期行为:

  1. 表单已提交到“subscribeSubmitAction”
  2. “subscribeSubmitAction”验证失败
  3. 调用回退到“subscribeAction”
  4. “$subscription”已设置并分配(不会发生) - 而“$subscription”始终为 NULL(但 subscription.test 已在 Fluid-Form 中设置)

我的猜测:

  • PropertyMapper 正在删除“subscription.childs”,因为它们不在“TrustedProperties”中 - 如何添加它们?
  • 为什么“$subscription”总是 NULL - 我不知道!

控制器:

namespace VENDOR\EXTENSION\Controller;
class EventController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
    public function initializeAction()
    {
        if ($this->arguments->hasArgument('subscription'))
        {
            //Try to add "subscription.childs" to the PropertyMapperConfiguration
            $subscriptionConfiguration = $this->arguments->getArgument('subscription')->getPropertyMappingConfiguration();
            $subscriptionConfiguration->allowProperties();
            $subscriptionConfiguration->forProperty('*')->allowAllProperties();
            $subscriptionConfiguration->forProperty('*')->allowCreationForSubProperty('*');
            $subscriptionConfiguration->forProperty('*')->forProperty('*')->allowAllProperties();
            $subscriptionConfiguration->forProperty('*')->forProperty('*')->allowCreationForSubProperty('*');
            $subscriptionConfiguration->forProperty('childs')->allowProperties();
            $subscriptionConfiguration->forProperty('childs')->allowCreationForSubProperty('*');
            $subscriptionConfiguration->forProperty('childs.*')->allowProperties();
            $subscriptionConfiguration->forProperty('childs.*')->allowCreationForSubProperty('*');

            print_r($this->arguments->getArgument('subscription')->getValue()); // => NULL
        }
    }

    /**
     * subscribeAction
     * @param  array $event
     * @param  array $subscription
     * @ignorevalidation $subscription
     */
    public function subscribeAction($event,$subscription = null)
    {
        print_r($subscription); // => NULL

        $this->view->assign('event',$event);
        $this->view->assign('subscription',$subscription);
    }

    /**
     * subscribeSubmitAction
     * @param array $event
     * @param array $subscription
     * @param string $g_recaptcha_reponse
     * @validate $g_recaptcha_reponse NotEmpty
     */
    public function subscribeSubmitAction($event,$subscription = null, $g_recaptcha_reponse = null)
    {
        /**
         * This Method will never be called because the Validation of "$g_recaptcha_reponse" must fail (it's empty)
         */
    }
}

模板:

<f:debug>{subscription}</f:debug>
<f:form action="subscribeSubmit" name="subscription" object="{subscription}">
    <f:form.hidden name='event[]' value='{event.uid}' />

    <f:form.textfield property="test" />

    <!--suppose this was added by javascript-->
    <input type="text" name="tx_extension_plugin[subscription][childs][0][test]" value="{subscription.childs.0.test}">

    <f:form.hidden name='g_recaptcha_reponse' value='' />

    <f:form.submit name="submit" value="Submit" />
</f:form>

【问题讨论】:

    标签: javascript typo3 datamapper fluid extbase


    【解决方案1】:

    我建议通过浏览器的网络面板检查请求。你看到那里的论点了吗?他们是否遵循tx_extension_plugin[subscription][... 的命名模式? 它们应该包含在 extbase 的请求中。 也许您不应该将它们添加到现有参数subscription 中,而是创建另一个参数。您可以以相同的方式对其进行验证,并且在 Fluid 中应该以相同的方式提供错误。

    “TrustedProperties”可能是正确的,但我不确定。但如果是这样,您绝对应该能够在您的 initializeAction 方法中解决这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多