Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » SS3 How to use a form as LeftAndMain

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: 427 Views
  • gshegosh81
    Avatar
    Community Member
    10 Posts

    SS3 How to use a form as LeftAndMain Link to this post

    Perhaps someone could outline what needs to be done to use a simple form as a custom LeftAndMain.

    What I've tried so far is to extend LeftAndMain and override getEditForm() where I have a single action like new FormAction('doMailingForm', 'Send'). It shows the form all right. I have it all added to $allowed_actions and it goes to doMailingForm method after submitting.

    But now, I'd like to return to the same form with a confirmation message. What do I then do in doMailingForm() method that services the form submission?

    This just gives me blank page:

       public function doMailingForm($data, $form) {
          $form->sessionMessage('Wysłano ' . time(), 'good');
          Controller::curr()->getRequest()->addHeader('X-Pjax', 'Content'); // Force a content refresh
          return Controller::curr()->redirect($this->Link());
       }

  • jak
    Avatar
    Community Member
    46 Posts

    Re: SS3 How to use a form as LeftAndMain Link to this post

    Two thoughts:
    1. Inside a Form, I usually do

    $this->controller->redirect($this->Link());
    return;


    Since you are already inside a Controller you can try

    $this->redirect($this->Link());
    return;


    or

    Controller::curr()->redirect($this->Link());
    return;

    2. You are using Polish strings. Are you encoding your php files as UTF? In that case check if your file starts with an (invisible) byte order mark. If so, remove it, since it can cause weird bugs.

    Looking at the code in SilverStripe, in a Controller they sometimes use:

    $form->sessionMessage($msg, 'good');
    return $this->getResponseNegotiator()->respond($this->request);


    and in a form:

    $this->sessionMessage($msg, 'good');
    $this->controller->redirect($target);

    In LeftAndMain they often use the getResponseNegotiator approach, so maybe try that.

  • gshegosh81
    Avatar
    Community Member
    10 Posts

    Re: SS3 How to use a form as LeftAndMain Link to this post

    I'll try returning void instead of what redirect() returns, thanks for the suggestion.
    Using responseNegotiator is also something I missed while looking through SS code, I'll try that

    As to UTF-8, I'm sure it's all right. I'm using Netbeans IDE (it's even better for PHP that it is for Java), so I got such stuff covered.

    427 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.