• 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.

Sorting dropdown labels/values

rbuelund

Member
Is it possible to sort dropdown labels/values in a form automatically - also with frontend add of new labels/values ??
 
Well - I might have found the solution myself. On the form I have a php extension that runs "onAfterProcess" with this code:
You'll have to change the id's in the array to match the id's of your dropdown elements. Can some of the developers confirm that this is a working method ?? I have same label/value in all dropdowns - I do not know what happens if they are not the same ??

$ids = array('16','32','68','131','165'); //Array of id's for dropdown elements that must be sorted
foreach ($ids as $id)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('params');
$query->from($db->quoteName('#__fabrik_elements'));
$query->where($db->quoteName('id')." = ".$db->quote($id));
$db->setQuery($query);
$row = $db->loadRow();

$params = $row[0];

//Sort
$parsed = get_string_between($row[0], "[", "]");
$old_modelstringarray = $parsed;
$modelarray = explode(",",$parsed);
asort($modelarray);
$new_modelstringarray = implode(",", $modelarray);

$params = str_replace($old_modelstringarray,$new_modelstringarray,$params);

//Update elements in db
$query = $db->getQuery(true);
$fields = array(
$db->quoteName('params') . ' = ' . $db->quote($params));
$conditions = array($db->quoteName('id') . ' = '.$id.'');
$query->update($db->quoteName('#__fabrik_elements'))->set($fields)->where($conditions);
$db->setQuery($query);
$result = $db->execute();
}

//Get string between []
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
 
hmm,
wouldn't it be better to use an extra list holding your values/labels and then use dbjoin elements pointing to this list instead of multiple dropdown elements with the same values/labels
 
Thoose who enter the data have to be able to do this at once in one form - so they have to be able to add new values on the form.
 
The different id's refer to different dropdowns on the form - which all needs sorting. Value = Label in all the different dropdowns - that was what i ment earlier in the thread.
 
There is also a FrontendAdd option in dbjoin.

At least you should not hack the fabrik elements but sort your output in dropdown's "Advanced" "Eval populate" section.
I assume there's an easier way to get the params - but I don't know.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top