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:

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

What's the correct way to publish a view after a form post.

Go to End



Community Member, 14 Posts

1 November 2008 at 3:42am


I'm wondering what the correct method ist to publish a different view after a form post. My use case: I want to filter a view via a form. I currently have this code:

        function FilterForm() {


		$actions = new FieldSet( 
			new FormAction( "filter", _t('UserDefinedForm.FILTER', 'Filtern') )


                return new Form( $this, "FilterForm", $fields, $actions );

	function filter($data, $form) {
		$ids = $this->someComplicatedFiltering($data);
		$_GET["ids"] = $ids;
		return Director::direct($this->data()->URLSegment."//select");

        function select() {
               return array("FilteredIds" => $_GET["ids"]);

It works, but I don't think it's nice because the Director starts from the very beginning.

I tried to make this work:


 $controller = new ModelAsController();
 $request = new HTTPRequest("GET", $this->data()->URLSegment.'//preview', $request->getVars(), $request->postVars());

 $result = $controller->handleRequest($request);
 return $result->getBody();

But this didn't work, it always showed me the default view of the object. I traced this to a code segment, where the request url (object_urlsegment/view) is "pushed" so it's object_urlsegment/object_urlsegment/view (I don't understand the use case of that).

So finally my question: What is the correct method to do this? There are two versions of this use case: Fetch a different view of the current object or fetch a view of a different object.

Thanks for your clarification,