/** * Looks at the validation condition & evaluates it * if evaluation is true then the validation rule is applied * * @param string $data Elements data * @param int $repeatCounter Repeat group counter * * @return bool apply validation */ public function shouldValidate($data, $repeatCounter = 0) { if (!$this->shouldValidateIn()) { return false; } if (!$this->shouldValidateOn()) { return false; } $params = $this->getParams(); $condition = $params->get($this->pluginName . '-validation_condition'); if ($condition == '') { return true; } $w = new FabrikWorker(); $groupModel = $this->elementModel->getGroupModel(); $inRepeat = $groupModel->canRepeat(); if ($inRepeat) { // Replace repeat data array with current repeatCounter value to ensure placeholders work. // E.g. return {'table___field}' == '1'; $f = JFilterInput::getInstance(); $post = $f->clean($_REQUEST, 'array'); $groupElements = $groupModel->getMyElements(); foreach ($groupElements as $element) { $name = $element->getFullName(true, false); $elementData = ArrayHelper::getValue($post, $name, array()); // things like buttons don't submit data, so check for empty if (!empty($elementData)) { $post[$name] = ArrayHelper::getValue($elementData, $repeatCounter, ''); $rawData = ArrayHelper::getValue($post, $name . '_raw', array()); $post[$name . '_raw'] = ArrayHelper::getValue($rawData, $repeatCounter, ''); } else { $post[$name] = ''; $post[$name . '_raw'] = ''; } } } else { $post = null; } $condition = trim($w->parseMessageForPlaceHolder($condition, $post)); FabrikWorker::clearEval(); $res = @eval($condition); FabrikWorker::logEval($res, 'Caught exception on eval in validation condition : %s'); if (is_null($res)) { return true; } return $res; }