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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   1525 Views

Avatar
gshegosh81

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

Avatar
jak

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

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

Avatar
gshegosh81

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.