Fabrik Joomla Component : Cheet Sheet Sample Code
Fabrik is one of the components in the Joomla CMS, the usefulness of the Fabrik component is a tool to easily create web applications. With Fabrik it is very easy to create forms and lists.
1. Update Form Data Sample Code
The command below is to update the data in the column after submitting the form$formModel->data['mahasiswa___data'] = "Testing";
2. Dropdown Element Advanced Populate Data Sample Code
This command displays a dropdown list by retrieving data from the database.$db = JFactory::getDbo();
$db->setQuery('SELECT id, nama FROM mahasiswa');
$rows = $db->loadObjectList();
$options[] = JHTML::_('select.option', 1000, 'Please select');
foreach ($rows as $row) {
$options[] = JHTML::_('select.option', $row->id, $row->nama);
}
return $options;
3. Dropdown Element Validation PHP Plugin Sample Code
The command below is to check the initial dropdown value.if ($data == 'Please select')
return false;
else
return true;
4. Element Validation PHP Plugin Sample Code
Below command to validate whether data as numeric/number// mengecek karakter angka
if (is_numeric($data))
return true;
else
return false;
5. Element Javascript Sample Code
$form = "form_" + Object.values(Fabrik.blocks)[0].id;
var $jurusan = Fabrik.getBlock($form).formElements.get("mahasiswa___jurusan");
var $keterangan = Fabrik.getBlock($form).formElements.get(
"mahasiswa___keterangan"
);
var $biaya = Fabrik.getBlock($form)
.formElements.get("mahasiswa___biaya")
.getValue();
if ($jurusan == "SI") {
Fabrik.getBlock($form).formElements.get("mahasiswa___biaya").set(100);
Fabrik.getBlock($form).formElements.get("mahasiswa___event").setValue("");
jQuery("#student___event > div:nth-child(2)").css("display", "none");
$keterangan.show();
} else {
Fabrik.getBlock($form).formElements.get("mahasiswa___biaya").set(100);
Fabrik.getBlock($form).formElements.get("mahasiswa___event").setValue("");
jQuery("#student___event > div:nth-child(2)").css("display", "");
$keterangan.hide();
}
/*
# sourceURL=filename.js
*/
6. Element Validation PHP Plugin Sample Code
The command below is to check the number of students majoring in Information Systems ( if ($data == “Information System”) { ) is equal to or greater than the number 50 (if ($row->total >= 50) ) and will block process if true.$db = JFactory::getDBO();
$app = JFactory::getApplication('site');
$user = JFactory::getUser();
if ($data == "Sistem Informasi") {
$query = "SELECT count(*) total FROM mahasiswa";
//JFactory::getApplication()->enqueueMessage("test". $query, 'error');
$db->setQuery($query);
$row = $db->loadObject();
if ($row) {
// block if exced the limit
if ($row->total >= 50)
return false;
else
return true;
} else
return true;
} else if (($data == "Teknik Informatika")) {
$query = "SELECT count(*) total FROM mahasiswa";
//JFactory::getApplication()->enqueueMessage("test". $query, 'error');
$db->setQuery($query);
$row = $db->loadObject();
if ($row) {
// block if exced the limit
if ($row->total >= 246) {
$event = JFactory::getApplication()->input->get("jurusan");
if ($event[0] == 'Komputer') {
return true;
} else {
$query = "SELECT id, email FROM mahasiswa WHERE email = '" . $user->get('email') . "'";
$db->setQuery($query);
$row2 = $db->loadObject();
if ($row2) {
return true;
} else
return false;
}
} else
return true;
} else
return true;
} else
return true;