/** * Shorthand method for inline validation * * @param array $data The data to be validated * @param array $validators The GUMP validators * @return mixed True(boolean) or the array of error messages */ public static function is_valid(array $data, array $validators) { $gump = new Gump(); $gump->validation_rules($validators); if ($gump->run($data) === false) { return $gump->get_readable_errors(false); } else { return true; } }
/** * Checks all entries for their correctness. Uses gump * Dies displaying a message on error * @param array $content the content of the csv-file */ private function csvCheckGump($content) { $errors = array(); $gump = new \Gump(); //workaround problem of pipe and commata in regex in gumpRules $gump->set_validation_rule_delimiter('||'); $gump->set_validation_rule_param_delimiter(',,'); $gump->rules($this->_gumpRules); foreach ($content as $row) { if (!$gump->run($row)) { $errors[] = $gump->get_readable_string_errors(true); } } if (count($errors)) { $errormsg = ''; foreach ($errors as $error) { $errormsg .= $error; } $this->_smarty->assign('backlink', 'index.php?module=' . 'administrator|System|User|UserUpdateWithSchoolyearChange|' . 'CsvImport'); $this->_interface->dieError(_g('Errors occured while importing the csv-file. ' . 'Please correct them and try again.<br />%1$s', $errormsg)); } }
protected function changeValidCheck() { require_once PATH_INCLUDE . '/gump.php'; $gump = new Gump(); $validation = array('id' => array('required|min_len,1|max_len,11|numeric', '', 'ID'), 'name' => array('required|min_len,1|max_len,255', '', 'name'), 'isEnabled' => array('required|boolean', '', 'ist Modul aktiviert'), 'displayInMenu' => array('required|boolean', '', 'wird in Menü angezeigt'), 'executablePath' => array('min_len,1|max_len,255', '', 'Asuführungspfad')); $gump->rules($validation); if ($gump->run($_POST)) { $this->changeBooleansParse(); return $this->changeCheckForSomethingChanged(); } else { die(json_encode(array('value' => 'error', 'message' => $gump->get_readable_string_errors(false)))); return false; } }