Submit Form in Dataobject - Silverstripe 3.1

限于喜欢 提交于 2019-12-02 09:23:21

问题


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();

}

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?

thx in advance


回答1:


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

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.



来源:https://stackoverflow.com/questions/20849211/submit-form-in-dataobject-silverstripe-3-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!