/** * Check the validity of the field based on the data submitted. Note that * this validation is performed on the wire data - i.e. that which is * submitted, before any setFormatter is run * * Called by the Editor / Join class instances - not expected for general * consumption - internal. * * @param array $data Data submitted from the client-side * @param Editor $editor Editor instance * @param * $id Row id that is being validated * @return boolean|string `true` if valid, string with error message if not * @internal */ public function validate($data, $editor, $id = null) { // Three cases for the validator - closure, string or null if (!count($this->_validator)) { return true; } $val = $this->_readProp($this->name(), $data); for ($i = 0, $ien = count($this->_validator); $i < $ien; $i++) { $validator = $this->_validator[$i]; $processData = $editor->inData(); $instances = array('action' => $processData['action'], 'id' => $id, 'field' => $this, 'editor' => $editor, 'db' => $editor->db()); if (is_string($validator['func'])) { // Don't require the Editor namespace if DataTables validator is given as a string if (strpos($validator['func'], "Validate::") === 0) { $res = call_user_func("\\DataTables\\Editor\\" . $validator['func'], $val, $data, $validator['opts'], $instances); } else { $res = call_user_func($validator['func'], $val, $data, $validator['opts'], $instances); } } else { $func = $validator['func']; $res = $func($val, $data, $this, $instances); } // Check if there was a validation error and if so, return it if ($res !== true) { return $res; } } // Validation methods all run, must be valid return true; }
/** * Check the validity of the field based on the data submitted. Note that * this validation is performed on the wire data - i.e. that which is * submitted, before any setFormatter is run * * Called by the Editor / Join class instances - not expected for general * consumption - internal. * @param array $data Data submitted from the client-side * @param Editor $editor Editor instance * @return boolean Indicate if a field is valid or not. * @internal */ public function validate($data, $editor) { // Three cases for the validator - closure, string or null if (!$this->_validator) { return true; } $val = $this->_readProp($this->name(), $data); if (is_string($this->_validator)) { $processData = $editor->inData(); $instances = array('action' => $processData['action'], 'id' => isset($processData['id']) ? str_replace($editor->idPrefix(), '', $processData['id']) : null, 'field' => $this, 'editor' => $editor, 'db' => $editor->db()); // Don't require the Editor namespace if DataTables validator is given as a string if (strpos($this->_validator, "Validate::") === 0) { return call_user_func("\\DataTables\\Editor\\" . $this->_validator, $val, $data, $this->_validatorOpts, $instances); } return call_user_func($this->_validator, $val, $data, $this->_validatorOpts, $instances); } $validator = $this->_validator; return $validator($val, $data, $this); }