Welcome, Guest
Username: Password: Remember me

TOPIC: Custom redirect after saving or cancelling a form

Custom redirect after saving or cancelling a form 25 May 2015 22:45 #13183

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
I have a view from a table item, for the sake of argument called 'table1'.

index.php?option=com_mycomponent&view=table1&cid[0]=1

I have created a link from this table which opens the item form of table2 i.e

index.php?option=com_mycomponent&view=table2&layout=addform

When I click SAVE and CLOSE or CANCEL, I go back to the GRID view for table2.. as expected

I need the page to actually go BACK to the view index.php?option=com_mycomponent&view=table1&cid[0]=1

How can I override this?
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

Custom redirect after saving or cancelling a form 26 May 2015 20:08 #13184

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
Hi,

Fork the controller for view2 the item controller, not the items), change the "applyRedirection" in the save/cancel function to redirect to your table1
Check the controllers and I think it will be obvious for you. If not, I can provide example code.

edit: code added

Like I said: create a fork/controllers/table1.php, copy the function cancel() from the original controllers/table1.php and paste it into you fork.
Then change in fork like this (or similar, default might be another view in your case)
public function cancel()
{
	$this->_result = $result = parent::cancel();
	$model = $this->getModel();

	//Define the redirections
	switch($this->getLayout() .'.'. $this->getTask())
	{
		case 'table1.cancel':
			$this->applyRedirection($result, array(
				'stay',
				'com_mycomponent.table1.default'
			), array(
				'cid[]' => null
			));
			break;

		default:
			$this->applyRedirection($result, array(
				'stay',
				'com_mycomponent.table1.default'
			));
			break;
	}
}

Something like that should work (tried in my own component and works)
Last Edit: 27 May 2015 13:30 by Romkabouter.
The administrator has disabled public write access.
Time to create page: 0.069 seconds

Get Started