Submit form in Dataobject - Silverstripe 3.1

I am using Aram's DataobjectAsPage module. Now I want to have a form on every DOaP site. I created such a form 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 The template is as follows

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

There is a form, but no data is sent. The same form works on a regular page, but not on a data object. how can i fix this?

thanks in advance

+1
source share
1 answer

The functions RegistrationFormand doRegistrationshould be located in your controller of the Holder page, and not in the data object.

, . , , .

+3

Source: https://habr.com/ru/post/1606446/


All Articles