List Pre-filter Variable passed to Custom Link?

hominid4

Member
Code:
Table: class
id|class_name|class_code
==========
1|Class One|CC-1-9861
2|Class Two|CC-2-3254

Table: student
id|student_name|class_id
==========
1|Bill|1
2|Susie|1
3|Larry|2
I have the two above simplified tables and are open to the public with no user access applied. A teacher is given the URL to the `student` table with a URL parameter that corresponds with their class' `class_code`:
"url_to_list?code=CC-1-9861" will only show Bill and Susie.

Everything works as needed, except when clicking on a record within the filtered list I get a "unable to find this record" error, because I don't have a custom link that includes the "code" URL parameter - which I can't figure how to do.

In the `student` List's 'Data > Pre-filter' I have:

Field: class_id
Condition: EQUALS
Value: code below
Type: Eval
Apply to: Public
PHP:
$classCode = $this->app->input->getString('code', '');

$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$tblClassEsc = $myDb->quoteName('class');
$classCodeEsc = $myDb->quote($classCode);

$myQuery = 'SELECT id FROM '.$tblClassEsc.' WHERE class_code = '.$classCodeEsc.' LIMIT 1';
$myDb->setQuery($myQuery);
$classId = $myDb->loadResult();

return $classId;
In the `student` list's elements I have `student_name` set to "Link to details", and for its Custom Link I'm needing to append the "code" URL parameter so that the record is found. Usually when I use the List's 'Data > Pre-filter' I'll append a placeholder matching the URL parameter in the element's Custom Link, however with the `student` Db table not having a `class_code` column and my pre-filter is using an Eval I can't figure how to "grab" the "code" URL parameter for the Custom Link, so that in the `student_name`'s Custom link I could have something like:

url_to_list/form/14/{rowid}?code={code}

I know I can add a corresponding `class_code` column to the `student` table and just use that placeholder within the Custom link, but I'm attempting first not having to depend on that.

Any suggestion on how I can "re-grab" the "code" URL parameter for the Custom Link?

Thanks!

Joomla: latest version
Fabrik: latest GitHub
 
Last edited:
?code={code}
Exactly this should do.
So
url_to_form...?code={code}
resp. (depending on your url)
url_to_form...&code={code}
 
Thank you Troester for the confirmation on that. Not quite sure why that's not working for me. I've tried different ways to get that to work but {code} will not populate with the value from the URL.

Am I understandingly correctly that {code} will auto-pull the value from the URL, so if the URL to the list is:
url_to_list...?code=123&test2=456&test3=789

And my Custom Link is:
url_to_form...?code={code}&test2={test2}&test3={test3}

Within the list, each link will become?:
url_to_form...?code=123&test2=456&test3=789

If so, that is extremely straightforward and I must be doing something else wrong.

For a barebones test, I recreated only the Class table in my testing site, which is a stock non-SEF Joomla install with Protostar, and the only component is Fabrik - both are the latest version and GitHub.

Table: class (List ID: 10 / Form ID: 14)
id|class_name|class_code
==========
1|Class One|123
2|Class Two|456

`class` List 'Data > Pre-filter' (image 1):

Field: class_code
Condition: EQUALS
Value: return $this->app->input->getString('code', '');
Type: Eval
Apply to: Public

`class_name` element Custom Link (image 2):

When linking to the list using the below URL, it pre-filters correctly:
mysite/index.php?option=com_fabrik&view=list&listid=10&code=123

This doesn't populate with the URL value:
index.php?option=com_fabrik&view=form&formid=14&rowid={rowid}&code={code}

This of course does work if I use the element placeholder, but was hoping to use the URL parameter instead:
index.php?option=com_fabrik&view=form&formid=14&rowid={rowid}&code={test_class___class_code}

The 3rd image shows {code} being empty in the browser's status.

Sorry for my long email, and if I've misunderstood what "?foo={foo}" does in the Custom link in regards to URL string args.

Thanks again!
list-data-prefilter.jpg element-custom-link.jpg list-page-status-url.jpg
 
Last edited:
Ah, ok. I thought your were using a custom edit/details URL (in list settings [Links]).
There it's pulling the URL params.

It seems the custom link in element settings doesn't.
 
Oh geez!! I totally blocked out using the List's 'Details > Links' settings instead, which I regularly use, and is more what I need anyways since I need this custom link to be globally for all the elements in the list in case other elements end up linking to the form as well. Was one of those weeks! But good to know this only works under the List's settings and not per element for future reference.

I added the 'Custom edit URL' there instead and is working just as needed. Thanks!
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top