在Dataobject中提交表单

在Dataobject中提交表单

本文介绍了在Dataobject中提交表单-Silverstripe 3.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Aram的DataobjectAsPage模块.现在,我想在每个DOaP站点上都有一个表格.我在Dataobject中创建了这样的表单

I'm using the DataobjectAsPage Module from Aram.Now I want to have a Form on each DOaP site. I created the form like this in my Dataobject

public function RegistrationForm() {

    $fields = new FieldList(
        new TextField('Name'),
        new TextField('PlusOne')
    );

    $actions = new FieldList(
        new FormAction('doRegistration', 'Submit')
    );

    return new Form($this, 'RegistrationForm', $fields, $actions);
}

public function doRegistration($data, $form) {

    $submission = new RegistrationObject();
    $form->saveInto($submission);
    $submission->EventObjectID = $this->ID;
    $submission->write();

    return $this->redirectBack();

}

我的Dataobject_show.ss模板看起来像这样

my Dataobject_show.ss Template looks like this

$RegistrationForm
<% loop Registrations %>
    $Name - $PlusOne
<% end_loop %>

有表单,但没有提交数据.相同的形式适用于普通页面,但不适用于数据对象.我该如何解决?

the form is there but the data doesn't submit. The same form works on a normal page but not on a dataobject. how can i fix this?

提前谢谢

推荐答案

您的RegistrationFormdoRegistration函数需要位于Holder页面控制器中,而不是数据对象中.

Your RegistrationForm and doRegistration functions need to be in your Holder page controller, not your data object.

这是因为数据对象页面实际上是由Holder控制器控制的.因此,如果您向该页面提交表单,则它实际上会提交给所有者页面.

This is because the data object page is actually controlled by the holder controller. So if you submit a form to this page, it actually submits to the holder page.

这篇关于在Dataobject中提交表单-Silverstripe 3.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 22:15