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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

SS3 How to use a form as LeftAndMain

Go to End

3 Posts   1107 Views


Community Member, 10 Posts

31 July 2012 at 9:14am

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


Community Member, 46 Posts

31 July 2012 at 9:25pm

Edited: 31/07/2012 9:26pm

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


Since you are already inside a Controller you can try


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

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


Community Member, 10 Posts

31 July 2012 at 9:29pm

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.