validation

trim all string fields in server.
(later bring this to AppModel or behavior level)
pull/63/head
noud 2012-11-26 12:19:06 +01:00
parent 80571386ad
commit fb41a0c2ca
1 changed files with 29 additions and 0 deletions

View File

@ -104,6 +104,35 @@ class Server extends AppModel {
),
);
/**
* Trim Array Elements (this should probably be in a behavior)
*
* @param $array
*/
protected function _trimArray(&$array = array()) {
// process some..
foreach ($array as &$field) {
// remove leading and trailing blanks
if (is_string($field)) {
$field = trim($field);
}
}
return $array;
}
/**
*
* @param $options
*/
public function beforeValidate($options = array()) {
parent::beforeValidate();
// process some..
$this->_trimArray($this->data['Server']);
return true;
}
public function isOwnedByOrg($serverid, $org) {
return $this->field('id', array('id' => $serverid, 'org' => $org)) === $serverid;
}