/** * Sets the value of the column * @param mixed $value new value * @param bool $validate validate the value, if typeDef is set * @return bool column set ok (check errors for details) */ public function setValue($value, $validate = TRUE) { if ($validate && !empty($this->typeDef)) { if (!PandraValidator::check($value, $this->name, $this->typeDef, $this->errors)) { if ($this->_parentCF instanceof PandraColumnContainer) { $this->_parentCF->errors[] = $this->errors[0]; } return FALSE; } } $this->value = $value; $this->setModified(); return TRUE; }
public function setKeyValidator(array $typeDefs) { if (empty($typeDefs)) { return; } foreach ($typeDefs as $typeDef) { if (!PandraValidator::exists($typeDef)) { throw new RuntimeException("{$typeDef} is not a Validator type"); } } $this->_typeDefKey = $typeDefs; }
public function testComplex() { $errors = array(); // test multiple validations per field $this->assertTrue(PandraValidator::check('http://www.phpgrease.net', 'urlLabel', array('url', 'maxlength=40'), $errors)); $this->assertFalse(PandraValidator::check('wwwphpgrease', 'urlLabel', array('url', 'maxlength=10'), $errors)); // expect errors for both the url and max length $fieldError = array_pop($errors); $this->assertTrue(count($fieldError['urlLabel']) == 2); // Test internal composites $this->assertTrue(PandraValidator::check('hello world', 'strRegularLabel', 'stringregular', $errors)); $this->assertFalse(PandraValidator::check('', 'strRegularLabel', 'stringregular', $errors)); $this->assertTrue(PandraValidator::check('hello world', 'str20Label', 'string20', $errors)); $this->assertFalse(PandraValidator::check('abcdefghijklmnopqrstuvwxyz', 'str20Label', 'string20', $errors)); }
/** * keyID mutator * @param string $keyID row key id * @param bool $validate use the defined key validator */ public function setKeyID($keyID, $validate = TRUE) { if ($validate && !empty($this->_typeDefKey)) { if (!PandraValidator::check($keyID, $this->name . " KEY", $this->_typeDefKey, $this->errors)) { if ($this->_parent !== NULL) { $this->_parent->registerError($this->errors[0]); } return FALSE; } } $this->_keyID = $keyID; }
} else { // everything OK. (fieldName's which are not columns in customer also being skipped) ajaxResult(); } exit; // 'save' post method validates all form data and saves. } elseif (isset($_POST['method']) && $_POST['method'] == 'save') { // Check that the session was started via a GET, and that the referrer is ourselves $honeyCatch = $_SESSION['REMOTE_ADDR'] != $_SERVER['REMOTE_ADDR'] || mktime() - $_SESSION['StartTime'] <= $minPostWindow || empty($_SERVER['HTTP_REFERER']); // 'url' will be a hidden field which should always remain empty, // and is not shown to the user. This will serve as the honeypot if (!$honeyCatch && !empty($_POST['url'])) { $honeyValue = $_POST['url']; $eTmp = ''; // validate an individual field $honeyCatch = !PandraValidator::check($_POST['url'], 'url', 'isempty', $etmp); } // It's just a regularly POST'ed form, so validate before we 'save' if (!$honeyCatch) { $vError = !$customer->populate($_POST); // PandraColumnFamily maintains a running log of all errors on the instance, in this case // we can just extract the unique column keys $validationErrors = array(); foreach ($customer->errors as $errors) { foreach ($errors as $column => $colError) { $validationErrors[$column] = array_pop($colError); } } } else { // Do something here if it looks to be a bot. // I'll just flag the session as bogus, and stop the script