Using a parameter to filter in CC5

tshirley 24 Mar, 2015
Hi again,

This is probably simple but I cannot see how to do it.

I want to pass a parameter to a CC5 listing so that it filters the list.

So for example if the calling form selects a certain value, to pass that value to the Connection and have it fliter by that value.

In this case I want the user to only see in the list, those records that they added, and not records that others added.

Thanks

Tim
GreyHead 24 Mar, 2015
Hi Tim,

Add a WHERE clause in the Conditions box that uses the User ID to set a limit.
<?php
$user = JFactory::getUser();
return array( 'user_id' => $user->id);
?>
assuming that user_id is the right column name in your table.

Bob
tshirley 24 Mar, 2015
Thanks Bob,

That will fix that specific scenario, however (and sorry for not being specific, my mistake) I was looking for the general case.

Suppose I want the user to select a value from a dropdown, have the form pass the selection to the connection and have the list show only records which match that value?

In CF, I would create a hidden field that picked up the incoming parameter and then use that in the condition. But I can't see how to create such a field in the connection.

Cheers

Tim
GreyHead 25 Mar, 2015
Hi Tim,

It would be similar.
<?php
$var = JRequest::getVar('var_name', 'default_value', 'get');
return array( 'column_name' => $var);
?>


If you set the default value to something that is never used then this will return an empty list if the var is missing from the URL.

If you want to specify the column as well as the value:
<?php
$col = JRequest::getVar('col_name', 'default_value', 'get');
$var = JRequest::getVar('var_name', 'default_value', 'get');
return array( $col => $var);
?>
Here you should set a default value for the column that does exist e.g. cf_id or id to avoid errors.

Bob

PSChronoForms automatically adds the URL variables to the $form->data array - it may be that CC does something similar but I don't recall what the variable name is without checking the code.
tshirley 25 Mar, 2015
Thanks! Works perfectly.

One more, if I may... different topic.

I can add a "New" Toolbar Button in CC5, and I add an action called "new" and set up the Form event to call.

But nothing happens when I click the New button. I guess there is some code that needs to be there to make the connection between the action and the button, can you suggest what it may be?

Cheers

Tim
This topic is locked and no more replies can be posted.