invictus
invictus

Reputation: 825

Submit Form in Dataobject - Silverstripe 3.1

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

Upvotes: 1

Views: 1564

Answers (1)

3dgoo
3dgoo

Reputation: 15804

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.

Upvotes: 3

Related Questions