Welcome, Guest
Username: Password: Remember me

TOPIC: [HOWTO GUIDE] Redirect to New record filter(s) not set

[HOWTO GUIDE] Redirect to New record filter(s) not set 27 Nov 2012 07:15 #5650

  • BTB300
  • BTB300's Avatar
  • Online
  • Moderator
  • Posts: 414
  • Thank you received: 130
  • Karma: 46
PLEASE NOTE THIS WAS AN OPEN TICKET THE PROBLEM HAS SINCE BEEN FIXED!
The solution below is offered as a workaround for those that experience similar issues as described below that don't want to (at present) rebuild, download and re-install their entire component

Hi Admin
I have been working on this for a few days maybe a week now
Have tried various Cook 2.0 builds with various config options over the past week and they all seem to have the same issue

The Issue
I have set the reuse value in save button of a form
It works perfectly when moving between forms related to the same table
but when moving between unrelated itemlayouts the filter value is not applied

I have setup a project called TEST REDIRECT to show what the issue is
and can confirm that the code changes suggested below work for this project.
please feel free to use or modify it to test as needed

My code changes are offered as a "workaround" (there may be more efficient methods or perhaps more secure methods)
but I will leave it up to you to decided the best way to implement it into the Builder and generated script

As i said above it works perfectly when moving between forms related to the same table such as
case 'registrationstepgroup.save':
	$this->applyRedirection($result, array(
	'com_testredirect.registrationdetail.registrationstepgroup',
	'com_testredirect.registrationdetail.registrationstepconfirm'
	), array(
		'cid[]' => $model->getState('registrationdetail.id'),
		'id' => $model->getState('registrationdetail.id')
	));
	break;

But when you want to pass to a form unrelated to the current table the filter_category is parsed and its value is available but not "preselected" when you move to a new record as shown below
case 'registrationstepconfirm.save':
	$this->applyRedirection($result, array(
		'com_testredirect.registrationdetail.registrationstepconfirm',
		'com_testredirect.groupmembersitem.groupmember'
	), array(
		'cid[]' => null,
		'filter_registration_id' => $model->getState('registrationdetail.id'),
	));
	break;

When you arrive at the "new record" form the related combo is not "preselected" using the filter_value passed from the previous form.

I believe that it is because the filters are not applied when redirected from tableone_itemlayout to tabletwo_itemlayout

In the model
/**
	* Method to get the data that should be injected in the form.
	*
	* @access	protected
	*
	* @return	mixed	The data for the form.
	*/
	protected function loadFormData()
	{
		// Check the session for previously entered form data.
		$data = JFactory::getApplication()->getUserState('com_testredirect.edit.groupmembersitem.data', array());

		if (empty($data)) {
			//Default values shown in the form for new item creation
			$data = $this->getItem();

			// Prime some default values.
			if ($this->getState('groupmembersitem.id') == 0)
			{
				$jinput = JFactory::getApplication()->input;
				
				$data->id = 0;
				$data->params = null;
				$data->member_name = null;
				$data->group_id = 0;
				$data->registration_id = $jinput->get('filter_registration_id',
				$this->getState('filter.registration_id'), 'INT');
				

			}
		}
		return $data;
	}

I have made the following changes and can confirm that the filter values are now applied to when redirected to a new record form
$jinput = JFactory::getApplication()->input;
				
// APPLY THE FILTERS: From the url
$this->setState('filter.registration_id','filter_registration_id', 'INT');

$data->id = 0;
$data->params = null;
$data->member_name = null;
$data->group_id = 0;
// Changed here to get the filter state to work
$data->registration_id = $jinput->get($this->getState('filter.registration_id','filter_registration_id', 'INT'), 'INT');

// OLD CODE
// $data->registration_id = $jinput->get('filter_registration_id', $this->getState('filter.registration_id'), 'INT');

Alternatively the following also works but is untested
$jinput = JFactory::getApplication()->input;

$data->id = 0;
$data->params = null;
$data->member_name = null;
$data->group_id = 0;
// Changed here to get the filter state to work
$data->registration_id = $jinput->get('filter_registration_id', 'INT');

And i can confirm that you are able to parse multiple variables such as
FROM THE CURRENT TABLE ITEM CONTROLLER
// ============================================================================
case 'registrationstepconfirm.save':
	$this->applyRedirection($result, array(
		'com_testredirect.registrationdetail.registrationstepconfirm',
		'com_testredirect.groupmembersitem.groupmember'
	), array(
		'cid[]' => null,
		'filter_registration_id' => $model->getState('registrationdetail.id'),
		// Add the second variable here such as
		'filter_group_id' => $item->groupname_id'
	));
	break;

// ==============================================================================

IN THE CURRENT TABLE MODEL
// ==============================================================================
$jinput = JFactory::getApplication()->input;
				
// APPLY THE FILTERS: From the url
$this->setState('filter.registration_id','filter_registration_id', 'INT');
// add the second variable filter such as below
$this->setState('filter.group_id','filter_group_id', 'INT');
				
$data->id = 0;
$data->params = null;
$data->member_name = null;
$data->group_id =  $jinput->get('filter_registration_id', $this->getState('filter.group_id'), 'INT');
$data->registration_id = $jinput->get('filter_registration_id', $this->getState('filter.registration_id'), 'INT');
// ==============================================================================

Anyhow I guess i can leave this one with you for now... B)

BTB300
Last Edit: 10 Dec 2012 10:15 by BTB300.
The administrator has disabled public write access.
The following user(s) said Thank You: VeCrea, JoomGuy

Re: [HOWTO GUIDE] Redirect to New record filter(s) not set 04 Dec 2012 11:46 #5814

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Thanks @BTB300

k+1
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: [HOWTO GUIDE] Redirect to New record filter(s) not set 07 Dec 2012 20:19 #5909

  • jcasanova
  • jcasanova's Avatar
  • Offline
  • Senior Member
  • Posts: 40
  • Thank you received: 1
  • Karma: 1
@audibleid

I'm trying to understand this.. but I can't ....

can you be so kind and create a example project in order to see the code.

because i'm trying to locate the code that BTB300 talk about but no results =(

please
The administrator has disabled public write access.

Re: [HOWTO GUIDE] Redirect to New record filter(s) not set 07 Dec 2012 22:59 #5919

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Sure, well, I don't believe a component is necessary but here's an example/instructions how to implement BTB300's redirection tutorial.

Cook handles this far better than joomla native although, because the code from cook is streamlined so well, you won't find a save function in your controllers/models as they utilise parent classes & super classes.Therefore, you need to:
  1. overload the save redirection in the controller like:
    public function save()
    {
      JRequest::checkToken() or JRequest::checkToken('get') or jexit(JText::_('JINVALID_TOKEN'));
      //Check the ACLs 
      $model = $this->getModel();
      $item = $model->getItem();
      if (!$model->canEdit($item))
        return false;
      $result = parent::save();
      //Catch the initializated JModel trough postSaveHook()
      $model = $this->model;
      //Define the redirections
      switch($this->getLayout() .'.'. $this->getTask())
    //==== REDIRECTORS GO BELOW HERE - see @BTB's solutions above in thread ====//
  2. Then, underneath the comment //==== REDIRECTORS GO... ====//, copy one of @BTB300's solutions, changing the component.view.layout in the redirectors as well as the view.task in the case/switch;
    • the first is the redirect if $result of the parent::save() == 0 OR NULL
    • the second is if if $result of the parent::save() == 1
  3. Be sure to close out of the switch()/cases and the save() function with:
    } // CLOSE SWITCH
    }//CLOSE FUNCTION
  4. Save and happy redirecting!
Hope it helps,

Gez ;)
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
Last Edit: 07 Dec 2012 23:07 by JoomGuy. Reason: ADDED INFO
The administrator has disabled public write access.
The following user(s) said Thank You: admin

Re: [HOWTO GUIDE] Redirect to New record filter(s) not set 07 Dec 2012 23:07 #5921

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
@jcasanova

Do you have a paid subscribtion ?
You must be able to download to do such things...
Coding is now a piece of cake
The administrator has disabled public write access.

Re: [HOWTO GUIDE] Redirect to New record filter(s) not set 07 Dec 2012 23:09 #5922

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
audibleid wrote:
Cook handles this far better than joomla native
:blush: Thanks :blush:
Coding is now a piece of cake
Last Edit: 07 Dec 2012 23:10 by admin.
The administrator has disabled public write access.

Re: [HOWTO GUIDE] Redirect to New record filter(s) not set 07 Dec 2012 23:25 #5924

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
one day, maybe joomla will be built in cook... ;)
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: [HOWTO GUIDE] Redirect to New record filter(s) not set 08 Dec 2012 12:29 #5936

  • jcasanova
  • jcasanova's Avatar
  • Offline
  • Senior Member
  • Posts: 40
  • Thank you received: 1
  • Karma: 1
admin wrote:
@jcasanova

Do you have a paid subscribtion ?
You must be able to download to do such things...

@admin yes I did, but not with this account because this is my personal acc.
The paid and working is "soportedo"
The administrator has disabled public write access.

Re: [HOWTO GUIDE] Redirect to New record filter(s) not set 10 Dec 2012 09:55 #5954

  • BTB300
  • BTB300's Avatar
  • Online
  • Moderator
  • Posts: 414
  • Thank you received: 130
  • Karma: 46
@jcasanova - The sample code will usually only be included if you define a redirect value on the tool bar buttons - such as apply, save...

To Do this in the builder
- right click the tool bar button
- properties box displayed
- choose the form to redirect to
Remember that it will only pass the current id (in an out of the box build)

for the reuse value
- if the field is a combo in the next form

- use filter_my_fieldname
- if it is an input box use my_fieldname

To understand how to work with redirects check this out it explains it in a little bit more depth

[HOW TO] Work with redirects => j-cook.pro/forum/33-developper-ressource...-with-redirects#5927
The administrator has disabled public write access.

Re: [HOWTO GUIDE] Redirect to New record filter(s) not set 10 Dec 2012 10:08 #5956

  • BTB300
  • BTB300's Avatar
  • Online
  • Moderator
  • Posts: 414
  • Thank you received: 130
  • Karma: 46
I Should probably also note that this was an open ticket for something that stopped working after some cook upgrades and the code provided was a workaround

The issue has since been fixed! (the filters were not being applied when passing between two views with unrelated tables)

- the code that i provided above may or may not be found in the downloaded source code (depending on how Admin decided to implement it)
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy

Re: [HOWTO GUIDE] Redirect to New record filter(s) not set 10 Dec 2012 10:40 #5959

  • jcasanova
  • jcasanova's Avatar
  • Offline
  • Senior Member
  • Posts: 40
  • Thank you received: 1
  • Karma: 1
BTB300 thanks...
@jcasanova - The sample code will usually only be included if you define a redirect value on the tool bar buttons - such as apply, save...

To Do this in the builder
- right click the tool bar button
- properties box displayed
- choose the form to redirect to
Remember that it will only pass the current id (in an out of the box build)

very usefull information. Yesterday I tried the implementation (link ) with the example given by @audibleid
and it worked.... it is good to know that it can be done from builder.

Thanks!
The administrator has disabled public write access.

Re: [HOWTO GUIDE] Redirect to New record filter(s) not set 10 Dec 2012 12:01 #5977

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Yes, but the builder cannot handle all the possibilities of the redirector.

Once the redirector features are complete and stable, I will design an interface to manage all possible cases.
(Not for tomorrow)

For instance, the reuse property can ONLY handle the current CID value. Do not ask me how to reuse another form entry. In this case you have to code (only one line)...

I am proud of my redirector...
It was a long way to design it.

Just a precision :
layout1, as somebody said, is almost of the case you layout from. But, it can also be another error page, even outside of your component (ex : an article, or home page... what you want)
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy
Time to create page: 0.113 seconds

Get Started