JoomlaSriLanka | Web Designer in Sri Lanka

Custom Row Ordering of Fabrik for Joomla forms & tables

Sometimes we need to display records on the front end of the website as a table or a list which is linked to a form that can make inquiries based on the row item selected . For example a list of business opportunities can be displayed on a page which visitors can apply online by clicking on a list item which pops up a form. 

On Joomla environment , there are number of extentions which can help us to implement this function. From those extensions, we have used Fabrik component many time to create special forms funtionality on Joomla websites which saved us lot of time and effort. 

Understanding and using Fabrik is pretty simple , but recently a client requested that he needs to order the rows of a table in a custom order which he decides. When this requirement came , we already has created the form using Fabrik component and it had no facility to implement custom ordering of records.

After little research, we managed to use the Fabriks Form settings to process a custom PHP file just after the data is stored which solved the problem.

Steps are 

  1. Add a row to the fabrik table ( i.e an element) named RowOrder
  2. Create a php file e.g. sort.php in htdocs\veenus\components\com_fabrik\plugins\form\fabrikphp\scripts 
  3. Add the following code to the sort.php

 

<?php
defined('_JEXEC') or die();
try {
$app =& JFactory::getApplication();
$post = JRequest::get('post');
$db = JFactory::getDBO();
$allocationid= JRequest::getVar('jos_Allocations___fabrik_internal_id');
$curroworder= JRequest::getVar('jos_Allocations___RowOrder');
$sqltext = "SELECT * FROM jos_Allocations ORDER BY RowOrder ASC";
$db->setQuery( $sqltext );
$rows=$db->loadObjectList();
$index = 1 ;
foreach($rows as $row ) {
if( $index == $curroworder){ $index++; }
if( $row->fabrik_internal_id != $allocationid ){
$sql = "update jos_Allocations set RowOrder=$index where fabrik_internal_id=$row->fabrik_internal_id";
$db->setQuery($sql);
$db->query();
$index++;
}
}
}
catch(Exception $e)
{
$app->enqueueMessage( JText::_( 'Error Occurred : ' . $e->getMessage() ), 'error' );
}
?>
<?php defined('_JEXEC') or die();try { $app =& JFactory::getApplication(); $post = JRequest::get('post'); $db = JFactory::getDBO(); $allocationid= JRequest::getVar('jos_Allocations___fabrik_internal_id'); $curroworder= JRequest::getVar('jos_Allocations___RowOrder'); $sqltext = "SELECT * FROM jos_Allocations ORDER BY RowOrder ASC"; $db->setQuery( $sqltext ); $rows=$db->loadObjectList(); $index = 1 ;  foreach($rows as $row ) {  if( $index == $curroworder){ $index++; }  if( $row->fabrik_internal_id != $allocationid ){ $sql = "update jos_Allocations set RowOrder=$index where fabrik_internal_id=$row->fabrik_internal_id"; $db->setQuery($sql); $db->query(); $index++; }  }}catch(Exception $e){ $app->enqueueMessage( JText::_( 'Error Occurred : ' . $e->getMessage() ), 'error' );
}?>


4. Setup a submission plugging for the relevent form to execute this php file after the data is stored.

Thats it. :)

 


Add comment


Security code
Refresh

 

Latest Work UG - New Zealand

uglydumpling.co.nz web design by sri lankan design company for new zealand

 

 

Paradise Vacations : Web Design | Joomla

 

 

paradisevacations1

 

Fly Sri Lanka : Web Design : Joomla

 

 

flysrilanka