本文整理汇总了PHP中Zend_Validate::getMessages方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Validate::getMessages方法的具体用法?PHP Zend_Validate::getMessages怎么用?PHP Zend_Validate::getMessages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Validate
的用法示例。
在下文中一共展示了Zend_Validate::getMessages方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBreakChainOnFailure
/**
* Ensures that a validator may break the chain
*
* @return void
*/
public function testBreakChainOnFailure()
{
$this->_validator->addValidator(new Zend_ValidateTest_False(), true)->addValidator(new Zend_ValidateTest_False());
$this->assertFalse($this->_validator->isValid(null));
$this->assertEquals(array('validation failed'), $this->_validator->getMessages());
$this->assertEquals(array('error'), $this->_validator->getErrors());
}
示例2: mailAction
public function mailAction()
{
$error = array();
$posts = array('First Name' => $_POST['first_name'], 'Last Name' => $_POST['last_name'], 'Email' => $_POST['email'], 'Message' => $_POST['message']);
$validatorChain = new Zend_Validate();
$validatorChain->addValidator(new Zend_Validate_NotEmpty());
$valid_email = new Zend_Validate_EmailAddress();
if ($valid_email->isValid($posts['Email'])) {
} else {
foreach ($valid_email->getMessages() as $message) {
$error[] = "Email {$message}\n";
}
}
foreach ($posts as $key => $post) {
if ($validatorChain->isValid($post)) {
} else {
foreach ($validatorChain->getMessages() as $message) {
$error[] = "{$key} {$message}\n";
}
}
}
if (count($error) != 0) {
$this->view->alerts = $error;
} else {
$to = 'illustratedpdx@gmail.com';
$subject = 'Email from Illustrated Portland';
$message = $posts['Message'];
$headers = "From: {$posts['First Name']} {$posts['Last Name']} <{$posts['Email']}>";
mail($to, $subject, $message, $headers);
//$this->view->alerts = array("Thank You! Your message has been sent.");
}
}
示例3: security
/**
* Security checks
*
* @throws Exception
* @return void
*/
public function security()
{
if (!$this->validator->isValid($this->get_request())) {
foreach ($this->validator->getMessages() as $message) {
throw new Exception($message);
}
}
}
示例4: __construct
/**
* Constructor.
*
* @param string $host OPTIONAL Hostname of remote connection (default: 127.0.0.1)
* @param integer $port OPTIONAL Port number (default: null)
* @throws Zend_Mail_Protocol_Exception
* @return void
*/
public function __construct($host = '127.0.0.1', $port = null)
{
$this->_validHost = new Zend_Validate();
$this->_validHost->addValidator(new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_ALL));
if (!$this->_validHost->isValid($host)) {
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception(join(', ', $this->_validHost->getMessages()));
}
$this->_host = $host;
$this->_port = $port;
}
示例5: __construct
public function __construct($arrParam = array(), $options = null)
{
//////////////////////////////////
//Kiem tra Name /////////////
//////////////////////////////////
if ($arrParam['action'] == 'add') {
$options = array('table' => 'da_album', 'field' => 'album_name');
} elseif ($arrParam['action'] == 'edit') {
$options = array('table' => 'da_album', 'field' => 'album_name', 'exclude' => array('field' => 'id', 'value' => $arrParam['id']));
}
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_NotEmpty(), true)->addValidator(new Zend_Validate_StringLength(3, 100), true);
if (!$validator->isValid($arrParam['album_name'])) {
$message = $validator->getMessages();
$this->_messageError['album_name'] = 'Tên album: ' . current($message);
$arrParam['album_name'] = '';
}
//////////////////////////////////
//Kiem tra Picture small ///////////
//////////////////////////////////
$upload = new Zend_File_Transfer_Adapter_Http();
$fileInfo = $upload->getFileInfo('picture');
$fileName = $fileInfo['picture']['name'];
if (!empty($fileName)) {
$upload->addValidator('Extension', true, array('jpg', 'gif', 'png'), 'picture');
$upload->addValidator('Size', true, array('min' => '2KB', 'max' => '1000KB'), 'picture');
if (!$upload->isValid('picture')) {
$message = $upload->getMessages();
$this->_messageError['picture'] = 'Hình ảnh đại diện: ' . current($message);
}
}
//////////////////////////////////
//Kiem tra Order /////////////
//////////////////////////////////
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_StringLength(1, 10), true)->addValidator(new Zend_Validate_Digits(), true);
if (!$validator->isValid($arrParam['order'])) {
$message = $validator->getMessages();
$this->_messageError['order'] = 'Sắp xếp: ' . current($message);
$arrParam['order'] = '';
}
//////////////////////////////////
//Kiem tra Status /////////////
//////////////////////////////////
if (empty($arrParam['status']) || !isset($arrParam['status'])) {
$arrParam['status'] = 0;
}
//========================================
// TRUYEN CAC GIA TRI DUNG VAO MANG $_arrData
//========================================
$this->_arrData = $arrParam;
}
示例6: isValidText
public function isValidText($value, $maxLenghtValue)
{
$validator = new Zend_Validate();
// Create a validator chain and add validators to it
$validator->addValidator(new Zend_Validate_NotEmpty())->addValidator(new Zend_Validate_StringLength(1, $maxLenghtValue));
// Validate the value
if ($validator->isValid($value)) {
return true;
} else {
// value failed validation; print reasons
foreach ($validator->getMessages() as $message) {
return array('Error' => $message);
}
}
}
示例7: _validateRule
/**
* @param array $validatorRule
* @return void
*/
protected function _validateRule(array $validatorRule)
{
/**
* Get one or more data values from input, and check for missing fields.
* Apply defaults if fields are missing.
*/
$data = array();
foreach ((array) $validatorRule[self::FIELDS] as $key => $field) {
if (array_key_exists($field, $this->_data)) {
$data[$field] = $this->_data[$field];
} else {
if (isset($validatorRule[self::DEFAULT_VALUE])) {
/** @todo according to this code default value can't be an array. It has to be reviewed */
if (!is_array($validatorRule[self::DEFAULT_VALUE])) {
// Default value is a scalar
$data[$field] = $validatorRule[self::DEFAULT_VALUE];
} else {
// Default value is an array. Search for corresponding key
if (isset($validatorRule[self::DEFAULT_VALUE][$key])) {
$data[$field] = $validatorRule[self::DEFAULT_VALUE][$key];
} else {
if ($validatorRule[self::PRESENCE] == self::PRESENCE_REQUIRED) {
// Default value array is provided, but it doesn't have an entry for current field
// and presence is required
$this->_missingFields[$validatorRule[self::RULE]][] = $this->_getMissingMessage($validatorRule[self::RULE], $field);
}
}
}
} else {
if ($validatorRule[self::PRESENCE] == self::PRESENCE_REQUIRED) {
$this->_missingFields[$validatorRule[self::RULE]][] = $this->_getMissingMessage($validatorRule[self::RULE], $field);
}
}
}
}
/**
* If any required fields are missing, break the loop.
*/
if (isset($this->_missingFields[$validatorRule[self::RULE]]) && count($this->_missingFields[$validatorRule[self::RULE]]) > 0) {
return;
}
/**
* Evaluate the inputs against the validator chain.
*/
if (count((array) $validatorRule[self::FIELDS]) > 1) {
if (!$validatorRule[self::ALLOW_EMPTY]) {
$emptyFieldsFound = false;
$errorsList = array();
$messages = array();
foreach ($data as $fieldKey => $field) {
// if there is no Zend_Validate_NotEmpty instance in the rules, we will use the default
if (!($notEmptyValidator = $this->_getNotEmptyValidatorInstance($validatorRule))) {
$notEmptyValidator = $this->_getValidator('NotEmpty');
$notEmptyValidator->setMessage($this->_getNotEmptyMessage($validatorRule[self::RULE], $fieldKey));
}
if (!$notEmptyValidator->isValid($field)) {
foreach ($notEmptyValidator->getMessages() as $messageKey => $message) {
if (!isset($messages[$messageKey])) {
$messages[$messageKey] = $message;
} else {
$messages[] = $message;
}
}
$errorsList[] = $notEmptyValidator->getErrors();
$emptyFieldsFound = true;
}
}
if ($emptyFieldsFound) {
$this->_invalidMessages[$validatorRule[self::RULE]] = $messages;
$this->_invalidErrors[$validatorRule[self::RULE]] = array_unique(call_user_func_array('array_merge', $errorsList));
return;
}
}
if (!$validatorRule[self::VALIDATOR_CHAIN]->isValid($data)) {
$this->_invalidMessages[$validatorRule[self::RULE]] = $validatorRule[self::VALIDATOR_CHAIN]->getMessages();
$this->_invalidErrors[$validatorRule[self::RULE]] = $validatorRule[self::VALIDATOR_CHAIN]->getErrors();
return;
}
} else {
if (count($data) > 0) {
// $data is actually a one element array
$fieldNames = array_keys($data);
$fieldName = reset($fieldNames);
$field = reset($data);
$failed = false;
if (!is_array($field)) {
$field = array($field);
}
// if there is no Zend_Validate_NotEmpty instance in the rules, we will use the default
if (!($notEmptyValidator = $this->_getNotEmptyValidatorInstance($validatorRule))) {
$notEmptyValidator = $this->_getValidator('NotEmpty');
$notEmptyValidator->setMessage($this->_getNotEmptyMessage($validatorRule[self::RULE], $fieldName));
}
if ($validatorRule[self::ALLOW_EMPTY]) {
$validatorChain = $validatorRule[self::VALIDATOR_CHAIN];
} else {
//.........这里部分代码省略.........
示例8: __construct
public function __construct($arrParam = array(), $options = null)
{
//////////////////////////////////
//Kiem tra group_name /////////////
//////////////////////////////////
if ($arrParam['action'] == 'add') {
$options = array('table' => 'da_user_group', 'field' => 'group_name');
} elseif ($arrParam['action'] == 'edit') {
$options = array('table' => 'da_user_group', 'field' => 'group_name', 'exclude' => array('field' => 'id', 'value' => $arrParam['id']));
}
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_NotEmpty(), true)->addValidator(new Zend_Validate_StringLength(3, 32), true)->addValidator(new Zend_Validate_Regex('#^[a-zA-Z0-9\\-_\\.\\s]+$#'), true)->addValidator(new Zend_Validate_Db_NoRecordExists($options), true);
if (!$validator->isValid($arrParam['group_name'])) {
$message = $validator->getMessages();
$this->_messageError['group_name'] = 'Group name: ' . current($message);
$arrParam['group_name'] = '';
}
//////////////////////////////////
//Kiem tra Avatar ///////////
//////////////////////////////////
$upload = new Zend_File_Transfer_Adapter_Http();
$fileInfo = $upload->getFileInfo('avatar');
$fileName = $fileInfo['avatar']['name'];
if (!empty($fileName)) {
$upload->addValidator('Extension', true, array('jpg', 'gif', 'png'), 'avatar');
$upload->addValidator('Size', true, array('min' => '2KB', 'max' => '1000KB'), 'avatar');
if (!$upload->isValid('avatar')) {
$message = $upload->getMessages();
$this->_messageError['avatar'] = 'Avatar: ' . current($message);
}
}
//////////////////////////////////
//Kiem tra ranking ///////////
//////////////////////////////////
$upload = new Zend_File_Transfer_Adapter_Http();
$fileInfo = $upload->getFileInfo('ranking');
$fileName = $fileInfo['ranking']['name'];
if (!empty($fileName)) {
$upload->addValidator('Extension', true, array('jpg', 'gif', 'png'), 'ranking');
$upload->addValidator('Size', true, array('min' => '2KB', 'max' => '1000KB'), 'ranking');
if (!$upload->isValid('ranking')) {
$message = $upload->getMessages();
$this->_messageError['ranking'] = 'Ranking: ' . current($message);
}
}
//////////////////////////////////
//Kiem tra Admin Control Panel /////////////
//////////////////////////////////
if (empty($arrParam['group_acp']) || !isset($arrParam['group_acp'])) {
$arrParam['group_acp'] = 0;
}
//////////////////////////////////
//Kiem tra Group Default /////////////
//////////////////////////////////
if (empty($arrParam['group_default']) || !isset($arrParam['group_default'])) {
$arrParam['group_default'] = 0;
}
//////////////////////////////////
//Kiem tra Status /////////////
//////////////////////////////////
if (empty($arrParam['status']) || !isset($arrParam['status'])) {
$arrParam['status'] = 0;
}
//////////////////////////////////
//Kiem tra order /////////////
//////////////////////////////////
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_Digits(), true);
if (!$validator->isValid($arrParam['order'])) {
$message = $validator->getMessages();
$this->_messageError['order'] = 'Order: ' . current($message);
$arrParam['order'] = '';
}
//========================================
// TRUYEN CAC GIA TRI DUNG VAO MANG $_arrData
//========================================
$this->_arrData = $arrParam;
}
示例9: isValid
/**
* Validate the normalized new value.
* Returns true if there are no validators or if validation passes,
* returns the array of error messages if validators fail.
*
* @return boolean|array
*/
public function isValid()
{
if ($this->_validator_chain === null) {
return true;
}
if ($this->_validator_chain->isValid($this->getNormalizedNewValue())) {
return true;
}
return $this->_validator_chain->getMessages();
}
示例10: __construct
public function __construct($arrParam = array(), $options = null)
{
$validateNotEmpty = new Zend_Validate_NotEmpty();
$validateNotEmpty->setMessage('Không được để trống.');
//////////////////////////////////
//Kiem tra fullname /////////////
//////////////////////////////////
$validateStrLength = new Zend_Validate_StringLength(3, 100);
$validateStrLength->setMessage('Giá trị nhập vào không hợp lệ, giá trị nhập vào là một chuỗi.', 'stringLengthInvalid');
$validateStrLength->setMessage("Chuỗi nhập vào phải lớn hơn %min% ký tự.", 'stringLengthTooShort');
$validateStrLength->setMessage("Chuỗi nhập vào phải nhỏ hơn %max% ký tự.", 'stringLengthTooLong');
$validator = new Zend_Validate();
$validator->addValidator($validateNotEmpty, true)->addValidator($validateStrLength, true);
if (!$validator->isValid($arrParam['fullname'])) {
$message = $validator->getMessages();
$this->_messageError['fullname'] = 'Họ và tên: ' . current($message);
$arrParam['fullname'] = '';
}
//////////////////////////////////
//Kiem tra email /////////////
//////////////////////////////////
$validateEmail = new Zend_Validate_EmailAddress();
$validateEmail->setMessage('Không hợp lệ, Giá trị nhập vào nên là chuỗi.', 'emailAddressInvalid');
$validateEmail->setMessage("'%value%' không đúng định dạng email.Email có dạng 'local-part@hostname'", 'emailAddressInvalidFormat');
$validateEmail->setMessage("'%value%' không đúng định dạng email.Email có dạng 'local-part@hostname'", 'emailAddressInvalidHostname');
$validator = new Zend_Validate();
$validator->addValidator($validateNotEmpty, true)->addValidator($validateEmail, true);
if (!$validator->isValid($arrParam['email'])) {
$message = $validator->getMessages();
$this->_messageError['email'] = 'Địa chỉ Email: ' . current($message);
$arrParam['email'] = '';
}
//////////////////////////////////
//Kiem tra title /////////////
//////////////////////////////////
$validator = new Zend_Validate();
$validator->addValidator($validateNotEmpty, true)->addValidator($validateStrLength, true);
if (!$validator->isValid($arrParam['title'])) {
$message = $validator->getMessages();
$this->_messageError['title'] = 'Tiêu đề ' . current($message);
$arrParam['title'] = '';
}
//////////////////////////////////
//Kiem tra Content /////////////
//////////////////////////////////
$validateStrLengthMsg = new Zend_Validate_StringLength(20);
$validateStrLengthMsg->setMessage('Giá trị nhập vào không hợp lệ, giá trị nhập vào là một chuỗi.', 'stringLengthInvalid');
$validateStrLengthMsg->setMessage("Chuỗi nhập vào phải lớn hơn %min% ký tự.", 'stringLengthTooShort');
$validateStrLengthMsg->setMessage("Chuỗi nhập vào phải nhỏ hơn %max% ký tự.", 'stringLengthTooLong');
$validator = new Zend_Validate();
$validator->addValidator($validateNotEmpty, true)->addValidator($validateStrLengthMsg, true);
if (!$validator->isValid($arrParam['message'])) {
$message = $validator->getMessages();
$this->_messageError['message'] = 'Nội dung: ' . current($message);
$arrParam['message'] = '';
}
//========================================
// TRUYEN CAC GIA TRI DUNG VAO MANG $_arrData
//========================================
$this->_arrData = $arrParam;
}
示例11: __construct
public function __construct($arrParam = array(), $options = null)
{
//////////////////////////////////
//Kiem tra User Name /////////////
//////////////////////////////////
if ($arrParam['action'] == 'add') {
$options = array('table' => 'da_users', 'field' => 'user_name');
} elseif ($arrParam['action'] == 'edit') {
$options = array('table' => 'da_users', 'field' => 'user_name', 'exclude' => array('field' => 'id', 'value' => $arrParam['id']));
}
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_NotEmpty(), true)->addValidator(new Zend_Validate_StringLength(3, 32), true)->addValidator(new Zend_Validate_Regex('#^[a-zA-Z0-9\\-_\\.\\s]+$#'), true)->addValidator(new Zend_Validate_Db_NoRecordExists($options), true);
if (!$validator->isValid($arrParam['user_name'])) {
$message = $validator->getMessages();
$this->_messageError['user_name'] = 'User name: ' . current($message);
$arrParam['user_name'] = '';
}
//////////////////////////////////
//Kiem tra User Avatar ///////////
//////////////////////////////////
$upload = new Zend_File_Transfer_Adapter_Http();
$fileInfo = $upload->getFileInfo('user_avatar');
$fileName = $fileInfo['user_avatar']['name'];
if (!empty($fileName)) {
$upload->addValidator('Extension', true, array('jpg', 'gif', 'png'), 'user_avatar');
$upload->addValidator('Size', true, array('min' => '2KB', 'max' => '1000KB'), 'user_avatar');
if (!$upload->isValid('user_avatar')) {
$message = $upload->getMessages();
$this->_messageError['user_avatar'] = 'Avatar: ' . current($message);
}
}
//////////////////////////////////
//Kiem tra Password /////////////
//////////////////////////////////
$flag = false;
if ($arrParam['action'] == 'add') {
$flag = true;
} elseif ($arrParam['action'] == 'edit') {
if (empty($arrParam['password'])) {
$flag = false;
} else {
$flag = true;
}
}
if ($flag == true) {
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_NotEmpty(), true)->addValidator(new Zend_Validate_StringLength(3, 32), true)->addValidator(new Zend_Validate_Regex('#^[a-zA-Z0-9@\\#\\$%\\^&\\*\\-\\+]+$#'), true);
if (!$validator->isValid($arrParam['password'])) {
$message = $validator->getMessages();
$this->_messageError['password'] = 'Password: ' . current($message);
}
}
//////////////////////////////////
//Kiem tra Email ////////////////
//////////////////////////////////
if ($arrParam['action'] == 'add') {
$options = array('table' => 'da_users', 'field' => 'email');
} elseif ($arrParam['action'] == 'edit') {
$options = array('table' => 'da_users', 'field' => 'email', 'exclude' => array('field' => 'id', 'value' => $arrParam['id']));
}
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_NotEmpty(), true)->addValidator(new Zend_Validate_EmailAddress(), true)->addValidator(new Zend_Validate_Db_NoRecordExists($options), true);
if (!$validator->isValid($arrParam['email'])) {
$message = $validator->getMessages();
$this->_messageError['email'] = 'Email: ' . current($message);
$arrParam['email'] = '';
}
//////////////////////////////////
//Kiem tra Group Name ////////////
//////////////////////////////////
if ($arrParam['group_id'] == 0) {
$this->_messageError['group_id'] = 'Group Name: Please choose Group Name';
}
//////////////////////////////////
//Kiem tra First Name /////////////
//////////////////////////////////
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_NotEmpty(), true)->addValidator(new Zend_Validate_StringLength(2), true);
if (!$validator->isValid($arrParam['first_name'])) {
$message = $validator->getMessages();
$this->_messageError['first_name'] = 'First Name: ' . current($message);
$arrParam['first_name'] = '';
}
//////////////////////////////////
//Kiem tra Last Name /////////////
//////////////////////////////////
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_NotEmpty(), true)->addValidator(new Zend_Validate_StringLength(2), true);
if (!$validator->isValid($arrParam['last_name'])) {
$message = $validator->getMessages();
$this->_messageError['last_name'] = 'Last Name: ' . current($message);
$arrParam['last_name'] = '';
}
//////////////////////////////////
//Kiem tra Birthday /////////////
//////////////////////////////////
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_NotEmpty(), true)->addValidator(new Zend_Validate_Date(array('format' => 'YYYY-mm-dd')), true);
if (!$validator->isValid($arrParam['birth_day'])) {
$message = $validator->getMessages();
//.........这里部分代码省略.........
示例12: _processValidatorRules
/**
* @return void
* @throws Zend_Validate_Exception
*/
protected function _processValidatorRules()
{
foreach ($this->_validatorRules as $ruleName => $validatorRule) {
if (!is_array($validatorRule)) {
$validatorRule = array($validatorRule);
}
$validatorList = array();
foreach ($validatorRule as $key => $value) {
if (is_int($key)) {
$validatorList[] = $value;
}
}
// set defaults
if (!isset($validatorRule[self::BREAK_CHAIN])) {
$validatorRule[self::BREAK_CHAIN] = false;
}
if (!isset($validatorRule[self::FIELD])) {
$validatorRule[self::FIELD] = $ruleName;
}
if (!isset($validatorRule[self::PRESENCE])) {
$validatorRule[self::PRESENCE] = self::PRESENCE_OPTIONAL;
}
$validatorChain = new Zend_Validate();
foreach ($validatorList as $validator) {
if (is_string($validator)) {
$validator = $this->_getValidator($validator);
}
if (!($validator && $validator instanceof Zend_Validate_Interface)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Expected object implementing Zend_Validate_Interface, got ' . get_class($validator));
}
$validatorChain->addValidator($validator, $validatorRule[self::BREAK_CHAIN]);
}
$field = $validatorRule[self::FIELD];
if (!isset($this->_data[$field]) && $validatorRule[self::PRESENCE] == self::PRESENCE_REQUIRED) {
$this->_missingFields[$field][] = "Field '{$field}' is required by rule {$ruleName}, but field is missing.";
continue;
}
// @todo: support multi-valued data inputs
if (!$validatorChain->isValid($this->_data[$field])) {
$this->_invalidFields[$field] = array_merge($this->_invalidFields, $validatorChain->getMessages());
continue;
}
$this->_validFields[$field] = $this->_data[$field];
}
/**
* Unset fields in $_data that have been added to other arrays.
* We have to wait until all rules have been processed because
* a given field may be referenced by multiple rules.
*/
foreach (array_merge(array_keys($this->_validFields), array_keys($this->_invalidFields), array_keys($this->_missingFields)) as $key) {
unset($this->_data[$key]);
}
/**
* Anything left over in $_data is an unknown field.
*/
$this->_unknownFields = $this->_data;
}
示例13: saveEditUserPwAction
/**
* Change the Password for the selected user
*
* Password is a salted hash, salt is defined in app config
*
* @return array
*/
public function saveEditUserPwAction()
{
$userModel = new Admin_Model_DbTable_Users();
$userRow = new Admin_Model_DbRow_User($userModel->find($this->request->getParam('id')));
if ($this->request->getParam('password_input', 1) === $this->request->getParam('password_confirm', 2) && $userRow->get('id')) {
// the if uses differnt default values for getParam() so that null or '' cannot be set, if fields are not present
$validate = new Zend_Validate();
$validate->addValidator(new Zend_Validate_NotEmpty(), new Zend_Validate_StringLength(8));
if ($validate->isValid($this->request->getParam('password_input'))) {
$userModel->updatePassword(md5($this->request->getParam('password_input') . Zend_Registry::get('password_salt')), $userRow->get('id'));
return $this->responseSuccess();
} else {
$error = $validate->getMessages();
}
} else {
$error = array('Passwords are not the same or unkown user');
}
return $this->responseFailure('Failed Saving informations', $error);
}
示例14: __construct
public function __construct($arrParam = array(), $options = null)
{
//////////////////////////////////
//Kiem tra Name /////////////
//////////////////////////////////
if ($arrParam['action'] == 'add') {
$options = array('table' => 'da_news', 'field' => 'title_news');
} elseif ($arrParam['action'] == 'edit') {
$options = array('table' => 'da_news', 'field' => 'title_news', 'exclude' => array('field' => 'news_id', 'value' => $arrParam['id']));
}
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_NotEmpty(), true)->addValidator(new Zend_Validate_StringLength(3, 100), true);
if (!$validator->isValid($arrParam['name'])) {
$message = $validator->getMessages();
$this->_messageError['name'] = 'Title: ' . current($message);
$arrParam['name'] = '';
}
//////////////////////////////////
//Kiem tra Picture small ///////////
//////////////////////////////////
$upload = new Zend_File_Transfer_Adapter_Http();
$fileInfo = $upload->getFileInfo('picture');
$fileName = $fileInfo['picture']['name'];
if (!empty($fileName)) {
$upload->addValidator('Extension', true, array('jpg', 'gif', 'png'), 'picture');
$upload->addValidator('Size', true, array('min' => '2KB', 'max' => '1000KB'), 'picture');
if (!$upload->isValid('picture')) {
$message = $upload->getMessages();
$this->_messageError['picture'] = 'Hình ảnh bài viết: ' . current($message);
}
}
//////////////////////////////////
//Kiem tra category /////////////
//////////////////////////////////
if ($arrParam['cat_id'] == 0) {
$this->_messageError['cat_id'] = 'Category : Please choose an category for item!';
}
//////////////////////////////////
//Kiem tra Order /////////////
//////////////////////////////////
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_StringLength(1, 10), true)->addValidator(new Zend_Validate_Digits(), true);
if (!$validator->isValid($arrParam['order'])) {
$message = $validator->getMessages();
$this->_messageError['order'] = 'Order: ' . current($message);
$arrParam['order'] = '';
}
//////////////////////////////////
//Kiem tra Status /////////////
//////////////////////////////////
if (empty($arrParam['status']) || !isset($arrParam['status'])) {
$arrParam['status'] = 0;
}
//////////////////////////////////
//Kiem tra News hot /////////////
//////////////////////////////////
if (empty($arrParam['newshot']) || !isset($arrParam['newshot'])) {
$arrParam['newshot'] = 0;
}
//////////////////////////////////
//Kiem tra Synopsis /////////////
//////////////////////////////////
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_StringLength(20), true);
if (!$validator->isValid($arrParam['synopsis'])) {
$message = $validator->getMessages();
$this->_messageError['synopsis'] = 'Synopsis: ' . current($message);
$arrParam['synopsis'] = '';
}
//////////////////////////////////
//Kiem tra Content /////////////
//////////////////////////////////
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_StringLength(20), true);
if (!$validator->isValid($arrParam['content'])) {
$message = $validator->getMessages();
$this->_messageError['content'] = 'Content: ' . current($message);
$arrParam['content'] = '';
}
//========================================
// TRUYEN CAC GIA TRI DUNG VAO MANG $_arrData
//========================================
$this->_arrData = $arrParam;
}
示例15: isValid
/**
* @return bool
*/
public function isValid()
{
$tableColumns = $this->_table->getColumns();
$dirtyColumns = $this->_data->getModified();
foreach ($dirtyColumns as $key => $value) {
unset($dirtyColumns[$key]);
$dirtyColumns[strtolower($key)] = $value;
}
#die(Zend_Debug::dump($tableColumns));
foreach ($tableColumns as $columnName => $columnStructure) {
if (array_key_exists($columnName, $dirtyColumns)) {
$validatorChain = new Zend_Validate();
// Notnull
if (array_key_exists('notnull', $columnStructure)) {
$validatorChain->addValidator(new Zend_Validate_NotEmpty(array('string' => true, 'empty_array' => true, 'null' => true, 'space' => true)));
}
// Email
if (array_key_exists('email', $columnStructure)) {
$validatorChain->addValidator(new Zend_Validate_EmailAddress());
}
// Notblank
if (array_key_exists('notblank', $columnStructure)) {
$validatorChain->addValidator(new Kebab_Validate_NotBlank());
}
// Nospace
if (array_key_exists('nospace', $columnStructure)) {
// check null
$validatorChain->addValidator(new Zend_Validate_NotEmpty(array('null' => true)));
// check space
$validatorChain->addValidator(new Zend_Validate_Regex(array('pattern' => '/\\s/')));
}
// Past
// Future
// Min Length
if (array_key_exists('minlength', $columnStructure)) {
$validatorChain->addValidator(new Zend_Validate_GreaterThan(array('min' => $columnStructure['minlength'])));
}
// Country
// Ip
if (array_key_exists('ip', $columnStructure)) {
$validatorChain->addValidator(new Zend_Validate_Ip());
}
// HtmlColor
// Range
if (array_key_exists('range', $columnStructure)) {
$validatorChain->addValidator(new Zend_Validate_Between(array('min' => $columnStructure['range'][0], 'max' => $columnStructure['range'][1])));
}
//Unique
if (array_key_exists('unique', $columnStructure)) {
$validatorChain->addValidator(new Kebab_Validate_Unique($columnName, $this->_data));
}
// Regex
if (array_key_exists('regexp', $columnStructure)) {
$validatorChain->addValidator(new Zend_Validate_Regex(array('pattern' => $columnStructure['regexp'])));
}
// Digits
if (array_key_exists('digits', $columnStructure)) {
$validatorChain->addValidator(new Zend_Validate_Digits());
}
// Date
if (array_key_exists('date', $columnStructure)) {
$validatorChain->addValidator(new Zend_Validate_Date());
}
// CC
if (array_key_exists('cc', $columnStructure)) {
$validatorChain->addValidator(new Zend_Validate_CreditCard());
}
// Unsigned
// Check All
if (!$validatorChain->isValid($dirtyColumns[$columnName])) {
$translator = Zend_Registry::get('Zend_Translate');
Zend_Validate_Abstract::setDefaultTranslator($translator);
$this->_errors[$columnName] = $validatorChain->getMessages();
}
unset($validatorChain);
}
}
if (count($this->_errors) > 0) {
return false;
} else {
return true;
}
}