【发布时间】:2015-08-03 08:24:48
【问题描述】:
由 JavaScript 添加到 Fluid-Form 的 Form-Elements 不会作为参数传递。
- 如何正确操作?
- 如何使用 JavaScript 动态添加表单域?
预期行为:
- 表单已提交到“subscribeSubmitAction”
- “subscribeSubmitAction”验证失败
- 调用回退到“subscribeAction”
- “$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