Jump to:

23550 Posts in 19336 Topics by 2890 members

General Questions

SilverStripe Forums » General Questions » form in page action not submitting

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: 1392 Views
  • ChrisBryer
    Community Member
    95 Posts

    form in page action not submitting Link to this post

    I am trying to create a front-end page editing capability, and set things up so that mysite.com/page/edit would return a (secured) customized page with a form to edit the page content. the problem that i have is that when i hit submit, the page returns to the same url, and nothing gets submitted. I dont know if this is because i am submitting from a url with an action in it or what. here is the code , any help would be appreciated:

    class CustomPage_Controller extends Page_Controller{
       function EditPage(){

          //this is called in a url, mysite.com/mypage/EditPage

          $fields = $this->EditableFields(); // correctly returns fields needed in form
          $actions = new FieldSet(
             new FormAction('UpdatePage', 'Update')
          $required = new RequiredFields(
          $form = new Form($this, "EditPage", $fields, $actions, $required);
          $newdata = array(
             'Title' => 'Editing '.$this->Title,
             'Content' => '',
             'Form' => $form
          return $this->customise($newdata)->renderWith(array('Page','Page'));
       function UpdatePage($data, $form){
        // ... code here, but this method never gets called...

    Thanks alot,

  • dalesaurus
    Community Member
    283 Posts

    Re: form in page action not submitting Link to this post

    Well it seems that the way you are putting the for in through customise() is causing the form to post back to itself instead of the UpdatePage action.

    See the post action in your form as rendered:

    <input type="submit" title="Update" value="Update" name="action_UpdatePage" id="Form_EditPage_action_UpdatePage" class="action"/>

    It sees EditPage as the form it should be calling to rebuild it and apply the data. Since your function doesn't return a Form object it just re-renders the page when it gets to the renderWith() call.

    You can:
    1. Move your form creation to a separate function EditPageForm and call it as a $EditPageForm in CustomPage_EditPage.ss template.
    2. Add the following arg to your existing code:

    function EditPage($data){

    The $data object will have all your posted data in the ->postVars array.

    1 is the intended SS way, 2 is the QnD way. Do as you will

  • ChrisBryer
    Community Member
    95 Posts

    Re: form in page action not submitting Link to this post

    thanks alot dalesaurus, that helped. i ended up using the template and it worked out pretty well. thanks again,

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.