We need your feedback on the need for updated payment plugins. Please go here and give us your feedback.
For running J!5.1 you must install Fabrik 4.1 See also Announcements
See Announcement
Please post subscription questions and issues here
We have resolved the issue with the J! updater and this will be fixed in the next release.
$db =Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
unset($formModel->_data);
* @param string $fullName full element name
* @param bool $raw get raw data
* @param mixed $default value
* @param string $repeatCount repeat count if needed
// To get the content of a simple Field element
$foo = $formModel->getElementData('mytable___foo');
// To get the content of the second occurence of an element in a repeat group (group repeats are numbered from 0)
$foo = $formModel->getElementData('my_repeat_table___foo', false, '', 1);
/*
*To get the raw value for a Database join element, which is set to display as a dropdown.
* Note that the data in a join element, or any element which has multiple value (checkbox, radiom etc)
* will (almost always) be an array, as it can contain multiple values. For a single value dropdown, we
* will typically just want the first (and only) value in that array, so the second line here simply extracts
* the single result from the array.
* Also note the use of the second argument, $raw, which fetches the 'value' rather than the 'label'
*/
$foo = $formModel->getElementData('mytable___somejoin', true);
$foo = is_array($foo) ? $foo[0] : $foo;
/*
* During a submission hook (like onBeforeProcess, onAfterProcess, etc), get the number of times a
* group has been repeated, and fetch each value of foo. You'll need to know the group ID of your group
* which is in the rightmost column of the main list of Groups on the backend. Here we'll use 123. On
* submit, the totals for each group's repeats are in a hidden form variable called fabrik_repeat_group,
* which we can fetch with the J! request API ($input->get()):
$app = Joomla\CMS\Factory::getApplication();
$input = $app->input; $group_id = 123;
$repeatTotals = $input->get('fabrik_repeat_group', array(0), 'array');
for ($repeats = 0; $repeats < $repeatTotals[$group_id]; $repeats++)
{
$foo = $formModel->getElementData('my_repeat_table___foo', false, $repeat);
// some code to do something with $foo goes here
}
/*
* An alternative approach to fetching all the repeated value for an element in a repeat group.
* This time, we'll just get the element's value, without specifying a repeatCount, in which case
* getElementData() will just hand us back an array which has all the repeated values.
* Typically when doing something like this, you will be wanting to fetch the coresponding value
* for another element in the same repeated instance of the group. So in this example, we'll use the key
* from a foreach() to grab another element's value. This example assumes we're going to do math on
* a 'cost' and 'qty', so specify $raw to make sure we get unformatted values.
*/
$costs = $formModel->getElementData('my_repeat_table___cost', true);
foreach ($costs as $key => $cost)
{
$qty = $formModel->getElementData('my_repeat_table___qty', true, 0, $key);
// do something with $cost and $qty
}
$formModel->_data; // for getTopContent, getBottomContent, getEndContent - use full element names: 'table___element'
$formModel->data //onload: use full element names 'table___element' e.g. $formModel->data['table___element']='abc';
$formModel->formData // onBeforeStore: use full element names 'table___element'
//for onAfterProcess - use short element names: 'element' - no table name (has issues with joined tables with identical column names (Jan. 2015)
onBeforeCalculation, onAfterProcess
$data['table___element']
// All versions of Fabrik also have a $formModel->fullFormData, which will contain the data keyed by full name, even onAfterProcess.
echo "<pre>";print_r($formModel->data);exit;
or
echo "<pre>";print_r($formModel->formData);exit;
or
echo "<pre>";print_r($data);exit;
$regions = $formModel->formData['countries___regions'];
$origData = $formModel->getOrigData()[0];
$originalFieldValue = $origData->mytable___myfield;
$formModel->updateFormData('tablename___elementname', 'string value', true);
If you need to update your data AFTER the form has been processed (and data has been written to the database), using onAfterProcess, note that the tablename___ prefix will have been removed from $formModel->formData[], so use $formModel->formDataWithTableName[] instead to access data. Also, using updateFormData() will have no effect, you have to manually run a query to update your table.
[HEADING=3]Conditionally updating a form's value on Save[/HEADING]
Lets say we want to update the field 'sport's value to 'badminton' when the field name's value is 'rob'. To do this the php would be:
[php]
$name = $formModel->formData['tablename___name'];
if ($name === 'rob')
{
$formModel->updateFormData('tablename___sport', 'badminton', true);
}
$formModel->data['table___element']='abc';
$formModel->data['table___element_raw']='abc';
// stop form being processed and close form without a message when saved
// will also close ajax modal form window
return false;
// The error message 'woops' will be assinged to the element 'tablename_elementname'
$formModel->errors['tablename___elementname'][] = 'woops!';
return false;
$formModel->getForm()->error = "Sorry, that's not going to work.";
$radio1 = (int)"{listname___radio1_raw}";
$radio2 = (int)"{listname___radio2_raw}";
$radio3 = (int)"{listname___radio3_raw}";
$total = $radio1 + $radio2 + $radio3;
$formModel->updateFormData("listname___total", $total, true);
if (!$formModel->isNewRecord()) {
$db = Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
$query = $db->getQuery(true);
$thisIp = $formModel->formData['contacts___ip'];
$query->select('COUNT(*)')->from('contacts')->where('ip = ' . $db->quote($thisIp));
$db->setQuery($query);
$total = $db->loadResult();
if ($total > 0)
{
return false;
}
}
return true;
$db = Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
$query = $db->getQuery(true);
$query->insert('tablename')->set('field = ' . $db->quote('bar'))
->set('field2 = ' . $db->quote('{tablename___elementname}'));
$db->setQuery($query);
$db->execute();
$id = $db->insertid();
// Update form data with insert id
$formModel->updateFormData('tablename___elementname2', $id);
// signup___course_id is the form field which contains the course Id you are signing up for
// We cast it to an array as it could be a select list or multiple select list.
$courseIds = (array) $formModel->formData['signup___course_id'];
// Get the db and the query
$db = Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
$query = $db->getQuery(true);
foreach ($courseIds as $courseId)
{
// Clear down any previous query
$query->clear();
// Update the query to decrease the value contained in the field "spaces" by 1 for the current course id.
$query->update('courses')->set('spaces = spaces - 1')->where('id = ' . (int) $courseId);
$db->setQuery($query);
$db->execute();
}
Code (Text):
foreach ($data[0] as $group) {
foreach ($group as $row) {
// your rowid will be in $row->__pk_val
// Elements will be in $row->tablename___fieldname
}
}
if ($formModel->copyingRow)
$element_value = $formModel->data['yourtable___elementname_raw'];
$elementModel = $formModel->getElement('yourtable___elementname');
$element_label = $elementModel->getEmailValue($element_value, $formModel->formDataWithTableName, 0);
//!J4
$app = Joomla\CMS\Factory::getApplication();
$app->enqueueMessage('some message you want to send','notice');