Set default values to dbjoin element rendered as checkbox

Hello,
Me again, sorry, but I'm surely getting better at fabriking, thanks to you !!
I saw tutorials, wikis and many posts related to this but couldn't figure out how to set up my own things.

I have 2 tables (both created by another component than Fabrik) :
- "months" is storing all possible months (well "all" should be 12 !)
- "trip_months" is storing possible months for a trip like this : *january*february*march* (it is a checkbox element in my component)

Now I want to grab my values in Fabrik :
- In my Fabrik "trips" form, I created a dbjoin element linked to months table and now have my (12) months rendered as checkboxes with values like january, february, march, april and so on....
- I want to select default months based on a trip previously selected by another dbjoin element in the same form

I tried this in eval box :
PHP:
$db = JFactory::getDbo();
$fk = $db->Quote('{trips___trip_id_raw}');
$query = "SELECT tripmonths FROM trip_months WHERE tripid = $fk)";
$db->setQuery($query);
$monthslistarray = $db->loadResult();
$monthslist = explode("*", $monthslistarray);
foreach ($monthslist as $month)
{
    $selected[] = $month;
}

See... it doesn't work... but I'm not the king of PHP...

Thanks for any help
 
I think you aren't far off with the code. Here's what I would do....

PHP:
$db = JFactory::getDbo();
$fk = $db->Quote('{trips___trip_id_raw}');
$query = "SELECT tripmonths FROM trip_months WHERE tripid = $fk";
$db->setQuery($query);
$monthslistarray = $db->loadResult();
$monthslist = explode("*", $monthslistarray);
 
return $monthslist;

So you had an extra ")" in the query
And any evaluated code has to "return" something.

I double checked this in the fabrik 3.0 master banch and there seemed to be a bug in this part of the code which I have fixed with this commit https://github.com/Fabrik/fabrik/commit/5e0684c3876d60bcd952cd73cf54bbe5bf1aaa4b. So you should update from the code there before continueing
 
Hello Rob, and thank you for answering,
I used your code in the "Eval options" field and updated the files you mentioned but still there's no default option selected...

- Do we have to use the "default value" field on top of the options settings or the "Eval options" field in Advanced settings ?
- When you say "any evaluated code has to return something", does that mean that I have to add something after the "return $monthslist;" ?

A bit lost...
 
hi
I used your code in the "Eval options" field and updated the files you mentioned but still there's no default option selected...
The PHP should go in the "default" text area
with the "eval default" turned on

I'm presuming your database join element is already set up to show the possible values and that you simply want to select those stored in trip_months;

When you say "any evaluated code has to return something", does that mean that I have to add something after the "return$monthslist;" ?

In your original PHP code you didn't have a "return $foo;"
The plugin takes the value that is returned from the eval code as the array of default values to use. If you don't return anything no defaults will be selected.
There's no need to add anything after return $monthlist, its precisely this line I was referring to when I said you need to return something (this line is the line that is doing the 'returning')
 
Hello and thanks for the explanation, it's clear now !
Unfortunately it still doesn't work...

My dbjoin shows the following multiselect list (I could do it with checkboxes, but same result)
HTML:
<select id="join___1390___voyages_repeat_liste_mois___liste_mois" class="fabrikinput inputbox" multiple="true" size="6" name="join[1390][voyages_repeat_liste_mois___liste_mois][]">
<option value="janvier">Janvier</option>
<option value="fevrier">F?vrier</option>
<option value="mars">Mars</option>
<option value="avril">Avril</option>
<option value="mai">Mai</option>
<option value="juin">Juin</option>
<option value="juillet">Juillet</option>
<option value="aout">Ao?t</option>
<option value="septembre">Septembre</option>
<option value="octobre">Octobre</option>
<option value="novembre">Novembre</option>
<option value="decembre">D?cembre</option>
</select>

the eval default is turned on and the PHP eval code is in the default box.

If I put this eval code in a calc element (to check if it works on one of my trips), it returns :
,mars,avril,mai,

... now why these options aren't selected in the dbjoin field of this same trip... mystery...
 
troseter I think Ecovoyager's query is right in that multiple values were stored in the legacy table separated by *

Ecovoyager can i check you are using the latest code from github?
Can you fill in your site's details in my sites (http://fabrikar.com/you/my-sites/) along with an admin account and details of which list/form this is for
 
ok so this is for editing existing records. In that case the default is not used as that's only applicable to new records.
I think I need to know a little more about your set up...

Is this a one time import of the data from the trip_months table?
Do you need to sync both ways, eg changes in the fabrik form's data must be sync'd back to the trip-months table?
 
Thanks for your answer and time spent to have a look,
I understand that default option is only applicable to new records... maybe you should add this info to the wiki ;-)

For my setup :
- I am using Jreviews forms to create and update my trips.
- trip_months is a table of Jreviews (well, I called it trip_months but it's the same table called jreviews_fields_options that stores all possible values for all Jreviews fields).

I use Fabrik lists for 2 things :
- use Fabrik lists and filters because they are far more powerful than Jreviews (so I have to copy Jreviews datas that will be used for lists template and filters in a Fabrik table called "trips").
- create new tables joined to "trips" for availability calendars, group departures, etc... and related searches/filters... such things can't be done with Jreviews.

Jreviews is easier to use than Fabrik for trips detail pages (with slideshows, etc...), so I think that my trips main datas will still be created and updated with Jreviews...

I need to update Fabrik "trips" table according to Jreviews datas and I was thinking of running a CRON to update Fabrik table from Jreviews every day.
Yet, some of these Jreviews fields are multiselect... and I would like to use them in Fabrik filters, but struggling... and that's the point of this thread !

Now you know the full story ! ;-)
Is that set up correct according to you ?
How would it be possible to copy the multiselect values from Jreviews ?
 
Ah, and of course, I first have to copy each Jreviews trip one by one to create my Fabrik "trips" rows... but you would have guessed ! ;-)
 
If I have understood correctly you then have two tables, one in jreviews and one in fabrik which basically have the same data? Also data may be stored in either of these tables. This really is going to cause issues, its never a good idea to have two sources of data that refer to the same information.

Personally I would remove the jreviews part all together, this would resolve all of your current issues, replacing it with an issue of just making the fabrik form user friendly. You can make slideshows in fabrik using the fileupload element, I'm not sure if there are other constraints that would stop this from being a valid option?
 
I agree with Rob on this one. Trying to manage this with two components and two tables for the same data is a nightmare in the making. I think you need to pick one component, and go with it, find ways to make that one component do what you need.

And given JReviews lack of customizable support for list / filter handling, as Rob says, it would probably be more feasible to do this all with Fabrik, and find ways to make your form input / display better suit your needs.

-- hugh
 
Thanks for your answers... You're right !
I was also thinking about it but too lazy to admit that it would be better to recreate/copy all fields/datas in Fabrik once for all and revamp the templates for Fabrik...
It will be a good thing to manage the whole thing with Fabrik for easier upgrade to Joomla! 3.x.
I think I will also remove Jomsocial and handle registration + profiles with Fabrik.

You will see me around for a few months... hope you also plan to continue Fabrik development and support ! :cool:
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top