• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Form on a page + related list in a module on same page

Suzzi

New Member
Hi.

I want a detail form to display on a page, with a list of related rows from another table displayed in a module beside it.

I can get it all working except that the list in the module shows ALL the rows from that table, and I only want to show rows based on a field common to the detail form and list. I open this page from two places, a menu item and from another fabrik list.

I'm new to fabrik and an old fashioned, and old!, programmer and have not had to use much php yet, but I suspect I will need to use some php here to get the value from the form and then filter the table? Or is it best to add a value to the url so that I have the filter information before the page displays? If so, how do I access that value in the module?

Any help appreciated, I have looked through the forums and can find mentions of this scenario but no information on how to get it working. (I am getting bogged down in how to pass values between pages/forms/lists/modules. I have only conquered databasejoins within a single form so far...)

Regards,
Suzzi
 
Funnily enough I was thinking about this yesterday.

You'll need to update to today's github to get the following to work

Edit your list module

Click on the prefilter button.

Select the element you want to filter on
condition : equals
value:

PHP:
return JFactory::getSession()->get('com_fabrik.form.1.data')['formelement___fullname_raw'];

* replace the 1 in com_fabrik.form.1.data with the form id that you are displaying in the page.

* replace 'formelement___fullname' with the full name of the form element you are showing - the _raw suffix says to use the raw value and not the formatted value.

Type: eval - this states to evaluate the value as a php expression


This set up will then tell the list module to filter so that the selected elements value must be the same as the value found in one of the forms fields. It will also work if you are showing a details view rather than a form.

I think due to the rendering order though you can do the inverse, that is to say set a prefilter on the component which take values from a form in a module view.
 
Thanks, I couldn't get it working with your code above, and tried variations of it, but got it working with breaking it up into two lines:
$course = JFactory::getSession()->get('com_fabrik.form.11.data');
return $course[htc_all_courses___course_id_raw];
 
Hello,

I am trying to achieve what was discussed here. I am working with the USDA Nutrient Database for Standard Reference. I have two tables with a common field (___NDB_No). Specifically, a table with foods (FOOD_DES), and a table with nutrient values (NUT_DATA). When viewing a food item, I want to display the nutrient values for that food in the Fabrik List Module. I have tried Rob's code and Suzzi's too. However, I have been unsuccessful in getting this to work. Any guidance would be appreciated.

Db table: FOOD_DES
Form ID: 2
Full Element Name: FOOD_DES___NDB_No

Db table: NUT_DATA
Form ID: 8
Full Element Name: NUT_DATA___Nutr_Val
Full Element Name: NUT_DATA___NDB_No


When using the the following code no data is returned:

return JFactory::getSession()->get('com_fabrik.form.8.data')['NUT_DATA___NDB_No_raw'];

$nutrval = JFactory::getSession()->get('com_fabrik.form.8.data');
return $nutrval[NUT_DATA___NDB_No_raw];


*Moved to Fabrik 3.1+ for Joomla 3.0+
 
Last edited:
In the second format you tried, put this as the second line (so before the return) ...

Code:
var_dump($nutrval);exit;

... then reload the page. This should dump the value of $nutrval to the browser.

Paste the result here ...

-- hugh
 
PS, althuogh I doubt it'll fix the problem, you will need quotes around the element name in that second return line, just like there are in the first example. Without the quotes, PHP will be tossing a warning.

-- hugh
 
Hi Hugh,

thank you for the help, very much appreciated. -Jeff

$nutrval = JFactory::getSession()->get('com_fabrik.form.8.data');
var_dump($nutrval);exit;
return $nutrval['NUT_DATA___NDB_No_raw'];


array(9) { ["aff168dae06d3a04cb12febe21c2118a"]=> string(37) "cZPM5AmivB1aPWtI.NPkdxqdTjWHwWVRukBHc" ["bb77330e0ef8929b4316d9b129ca2e1a"]=> string(32) "c614a09a129bc13a86f342ecf4022f80" ["2668959dcda881891b91424daea0ba8c"]=> string(32) "2c4d60272cf53e81243e274f288784dd" ["option"]=> string(10) "com_fabrik" ["Itemid"]=> NULL ["view"]=> string(7) "details" ["formid"]=> string(1) "8" ["rowid"]=> string(0) "" ["format"]=> string(4) "html" }
 
Hmmm. Is form 8 the one in the main page, or the module? From your description, I think you need to be looking at 2, not 8.

-- hugh
 
Hugh,

thank you for the guidance. I had tried that, but not with the var_dump($nutrval);exit; code.

If I try
$nutrval = JFactory::getSession()->get('com_fabrik.form.2.data');
var_dump($nutrval);exit;

I get
array(39) { ["FOOD_DES___NDB_No"]=> string(4) "1001" ["FOOD_DES___NDB_No_raw"]=> string(4) "1001" ["FOOD_DES___FdGrp_Cd_raw"]=> string(4) "0100" ["FOOD_DES___FdGrp_Cd"]=> string(22) "Dairy and Egg Products" ["FOOD_DES___Long_Desc"]=> string(14) "Butter, salted" ["FOOD_DES___Long_Desc_raw"]=> string(14) "Butter, salted" ["FOOD_DES___Shrt_Desc"]=> string(16) "BUTTER,WITH SALT" ["FOOD_DES___Shrt_Desc_raw"]=> string(16) "BUTTER,WITH SALT" ["FOOD_DES___ComName"]=> NULL ["FOOD_DES___ComName_raw"]=> NULL ["FOOD_DES___ManufacName"]=> NULL ["FOOD_DES___ManufacName_raw"]=> NULL ["FOOD_DES___Survey"]=> string(1) "Y" ["FOOD_DES___Survey_raw"]=> string(1) "Y" ["FOOD_DES___Ref_Desc"]=> NULL ["FOOD_DES___Ref_Desc_raw"]=> NULL ["FOOD_DES___Refuse"]=> string(1) "0" ["FOOD_DES___Refuse_raw"]=> string(1) "0" ["FOOD_DES___SciName"]=> NULL ["FOOD_DES___SciName_raw"]=> NULL ["FOOD_DES___N_Factor"]=> string(4) "6.38" ["FOOD_DES___N_Factor_raw"]=> string(4) "6.38" ["FOOD_DES___Pro_Factor"]=> string(4) "4.27" ["FOOD_DES___Pro_Factor_raw"]=> string(4) "4.27" ["FOOD_DES___Fat_Factor"]=> string(4) "8.79" ["FOOD_DES___Fat_Factor_raw"]=> string(4) "8.79" ["FOOD_DES___CHO_Factor"]=> string(4) "3.87" ["FOOD_DES___CHO_Factor_raw"]=> string(4) "3.87" ["slug"]=> string(4) "1001" ["__pk_val"]=> string(4) "1001" ["aff168dae06d3a04cb12febe21c2118a"]=> string(37) "cZPM5AmivB1aPWtI.NPkdxqdTjWHwWVRukBHc" ["bb77330e0ef8929b4316d9b129ca2e1a"]=> string(32) "c614a09a129bc13a86f342ecf4022f80" ["2668959dcda881891b91424daea0ba8c"]=> string(32) "2c4d60272cf53e81243e274f288784dd" ["Itemid"]=> string(3) "112" ["option"]=> string(10) "com_fabrik" ["view"]=> string(7) "details" ["formid"]=> string(1) "2" ["rowid"]=> string(4) "1001" ["format"]=> string(4) "html" }

So it is returning the first record of Db table: FOOD_DES. But what I really want is the nutrient values from NUT_DATA where the NUT_DATA___NDB_No is the same as the FOOD_DES___NDB_No.

If i remove the "var_dump($nutrval);exit;" from the aforementioned eval, the list module still does not display any data, nor does the evals listed below. Sorry, I am confused as to how this may work in order to display the related records. Namely "When viewing a food item, I want to display the nutrient values for that food in the Fabrik List Module"

$nutrval = JFactory::getSession()->get('com_fabrik.form.2.data');
return $nutrval['NUT_DATA___NDB_No_raw'];

$nutrval = JFactory::getSession()->get('com_fabrik.form.2.data');
return $nutrval['FOOD_DES___NDB_No_raw'];

Again, I greatly appreciate your guidance and hope we can figure this out.
 
It's possible that Rob may have been wrong about the rendering order. I'm not sure if the component or the module will be rendered first, or if the order has changed since he wrote that post back in 2012. The problem being, if the module gets rendered first, then the data for the component's form won't be in the session.

@rob ?

-- hugh
 
Hugh,

I figured it out and got it to work. Part of the problem which I did not notice is that the common field FOOD_DES___NDB_No in the table FOOD_DES is a 5 digit number of type varchar, some of which have values with a preceding zero. What is happening is that if I open the table FOOD_DES in Fabrik, it changes the field from type varchar to type integer and trips out the preceding zero. I suspect that the reason why Fabrik is doing this is due to the fact that the field is the primary key.



Here is the eval value that achieves what I described as the objective. I figure it would be good to have it documented here in case someone else is attempting a similar solution.

$nutrval = JFactory::getSession()->get('com_fabrik.form.2.data');
return $nutrval['FOOD_DES___NDB_No_raw'];



In wrapping up this discussion, a couple questions if you know.

1. Is there a way to prevent Fabrik from modifying the field type and subsequently stripping out the preceding zero? I need to modify the list settings, without having the field type changed.

2. Can you think of a way to only display the Fabrik List Module on the details view? The way I am assigning the module it to a menu item that points to the list, which subsequently is displayed when clicking to the list item details. However, the module is not relevant on the list view, only the details view. Also indicative of this fact is that the prefilter is cached from the details view and displays the last value on the list view. (I hope I am describing this accurately)



Thanks again for your help. I am learning a lot and realizing what great potential is possible with Fabrik.
 
You can stop us from changing field types by setting "Alter existing fields" to No (or "New only") in the list's advanced settings. However, I can't guarantee that you won't see unexpected results using a varchar PK with leading 0's. Maybe nothing which would affect you - the most obvious thing I can think of would be if you ordered by the PK element, where it would then order alphabetically rather than numerically. But there may be some more subtle issues, as our code has been built entirely around the assumption that PK's are integers.

For 2, you'd have to use some 3rd party solution which provides custom modules, and put some PHP code in to check the view type in the query string. Then instead of using the Fabrik form module, render the {fabrik ...} plugin instead, by doing an ...

echo "{fabrik view=form ...}";

-- hugh
 
I have to say that you are quite brilliant, not to mention that the support and community here really exemplifies open source software at its best.

Yeah, I was just looking into Advanced Module Manger Pro feature Custom PHP: Create your own custom php check. This will make it possible to make assign the module to virtually anything you can think of. If/when I figure it out I will share my results.

Jeff
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top