Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[SOLVED] Form submissions creating pages in CMS


Go to End


3 Posts   1141 Views

Avatar
Sparrowhawk

Community Member, 33 Posts

24 November 2009 at 1:48am

Edited: 24/11/2009 2:37am

I am probably doing this all wrong!

I have a questionnaire which I have modelled as a page, ProgrammeLaunchPage

The form works as expected, validation is OK, and when a user submits the form a record is created in the ProgrammeLaunchPage_Live table

The problem is, the page is also added to the CMS, as a blank empty entry with no page type.

What I'd like: keep the records saving into the table, but don't have the rogue pages being created.

Here is the ProgrammeLaunchPage_Controller code I use to save the submitted form values:

    public function doSaveForm($data, $form) {

        $success = 1;

        try {
            $plp = new ProgrammeLaunchPage();
            $form->saveInto($plp);
            $plp->write();

        } catch (Exception $e) {
            $success = 0;
        }

        Director::redirect(Director::baseURL(). $this->URLSegment . '/?success=' . $success);
    }

Avatar
Sparrowhawk

Community Member, 33 Posts

24 November 2009 at 1:59am

Should I be saving into a custom database table instead? If so, how would I do that using sapphire? Many thanks

Avatar
Sparrowhawk

Community Member, 33 Posts

24 November 2009 at 2:05am

Edited: 24/11/2009 2:37am

OK, I think I have worked it out:

I should have 2 classes: one sublcassed from Page (as I currently have) ,and one form DataObject. When I save it should be into the one from DataObject.

EDIT: yes, that solved it. Obvious when you think about it I suppose!