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.

General Questions

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

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

[SOLVED] Form submissions creating pages in CMS


Reply

3 Posts   759 Views

Avatar
Sparrowhawk

24 November 2009 at 1:48am (Last edited: 24 November 2009 2:37am), Community Member, 33 Posts

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

24 November 2009 at 1:59am Community Member, 33 Posts

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

Avatar
Sparrowhawk

24 November 2009 at 2:05am (Last edited: 24 November 2009 2:37am), Community Member, 33 Posts

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!