Jump to:

23361 Posts in 18124 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » [SOLVED] Form submissions creating pages in CMS

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

Page: 1
Go to End
Author Topic: 726 Views
  • Sparrowhawk
    Avatar
    Community Member
    33 Posts

    [SOLVED] Form submissions creating pages in CMS Link to this post

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

  • Sparrowhawk
    Avatar
    Community Member
    33 Posts

    Re: [SOLVED] Form submissions creating pages in CMS Link to this post

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

  • Sparrowhawk
    Avatar
    Community Member
    33 Posts

    Re: [SOLVED] Form submissions creating pages in CMS Link to this post

    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!

    726 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.