public function __construct($data, $sodu, $tongno) { $val = new Zend_Validate_NotEmpty(); $num = new Zend_Validate_Digits(); $date = new Zend_Validate_Date(array('format' => 'dd/MM/yyyy')); if ($val->isValid($data['tenhoadon']) == false) { $this->messages[] = "Tên Hóa Đơn không được trống"; } if ($val->isValid($data['tienthanhtoan']) == false) { $this->messages[] = "Tiền thanh toán được trống"; } else { if ($num->isValid($data['tienthanhtoan']) == false) { $this->messages[] = "Tiền thanh toán phải là số"; } else { if ($data['tienthanhtoan'] > $sodu) { $this->messages[] = "Tiền thanh toán phải nhỏ hơn số dư"; } else { if ($data['tienthanhtoan'] > $tongno) { $this->messages[] = "Tiền thanh toán không lớn hơn số nợ"; } else { if ($data['tienthanhtoan'] < 0) { $this->messages[] = "Tiền thanh toán phải là số dương"; } } } } } if ($date->isValid($data['ngaythanhtoan']) == false) { $this->messages[] = "Ngày thanh toán không đúng"; } }
/** * @group ZF-11267 * If we pass in a validator instance that has a preset custom message, this * message should be used. */ function testIfCustomMessagesOnValidatorInstancesCanBeUsed() { // test with a Digits validator require_once 'Zend/Validate/Digits.php'; require_once 'Zend/Validate/NotEmpty.php'; $data = array('field1' => 'invalid data'); $customMessage = 'Hey, that\'s not a Digit!!!'; $validator = new Zend_Validate_Digits(); $validator->setMessage($customMessage, 'notDigits'); $this->assertFalse($validator->isValid('foo'), 'standalone validator thinks \'foo\' is a valid digit'); $messages = $validator->getMessages(); $this->assertSame($messages['notDigits'], $customMessage, 'stanalone validator does not have custom message'); $validators = array('field1' => $validator); $input = new Zend_Filter_Input(null, $validators, $data); $this->assertFalse($input->isValid(), 'invalid input is valid'); $messages = $input->getMessages(); $this->assertSame($messages['field1']['notDigits'], $customMessage, 'The custom message is not used'); // test with a NotEmpty validator $data = array('field1' => ''); $customMessage = 'You should really supply a value...'; $validator = new Zend_Validate_NotEmpty(); $validator->setMessage($customMessage, 'isEmpty'); $this->assertFalse($validator->isValid(''), 'standalone validator thinks \'\' is not empty'); $messages = $validator->getMessages(); $this->assertSame($messages['isEmpty'], $customMessage, 'stanalone NotEmpty validator does not have custom message'); $validators = array('field1' => $validator); $input = new Zend_Filter_Input(null, $validators, $data); $this->assertFalse($input->isValid(), 'invalid input is valid'); $messages = $input->getMessages(); $this->assertSame($messages['field1']['isEmpty'], $customMessage, 'For the NotEmpty validator the custom message is not used'); }
public function __construct($data) { $val = new Zend_Validate_NotEmpty(); $num = new Zend_Validate_Digits(); if ($val->isValid($data['ten']) == false) { $this->messages[] = "Tên nhà cung cấp không được trống"; } if ($num->isValid($data['sdt']) == false) { $this->messages[] = "Số điện thoại phải là số"; } if ($val->isValid($data['sdt']) == false) { $this->messages[] = "Số điện thoại không được trống"; } if ($num->isValid($data['fax']) == false) { $this->messages[] = "Số fax phải là số"; } if ($val->isValid($data['fax']) == false) { $this->messages[] = "Số fax không được trống"; } if (array_key_exists('no', $data)) { if ($num->isValid($data['no']) == false) { $this->messages[] = "Nợ phải là số"; } if ($val->isValid($data['no']) == false) { $this->messages[] = "Nợ không được trống"; } } }
public function createForm($makhohang) { $this->setDisableLoadDefaultDecorators(true); $this->setDecorators(array(array('ViewScript', array('viewScript' => 'formmoi/ctpsession.phtml')), 'Form')); Zend_Session::start(); $mysession = new Zend_Session_Namespace('XuLyDonHang'); $num = new Zend_Validate_Digits(); if ($mysession->checktp != null) { foreach ($mysession->checktp as $item) { if ($num->isValid($item)) { $them = $this->createElement('checkbox', '' . $item, array('decorators' => array('ViewHelper'))); $them->setAttrib('class', 'checkbox'); $this->addElement($them); } } } $khohang = $this->createElement('hidden', 'mykhohang', array('decorators' => array('ViewHelper'))); $khohang->setAttrib('class', 'formEdit')->setValue($makhohang); $this->addElement($khohang); $giaohang = $this->createElement('submit', 'giaohang', array('decorators' => array('ViewHelper'), 'label' => 'Giao Hàng')); $giaohang->setAttrib('class', 'btn btn-primary'); $this->addElement($giaohang); $bochon = $this->createElement('submit', 'bochon', array('decorators' => array('ViewHelper'), 'label' => 'Bỏ Chọn')); $bochon->setAttrib('class', 'btn btn-primary'); $this->addElement($bochon); }
public function __construct($data) { $val = new Zend_Validate_NotEmpty(); $num = new Zend_Validate_Digits(); $date = new Zend_Validate_Date(array('format' => 'dd/MM/yyyy')); if ($val->isValid($data['tendonhang']) == false) { $this->messages[] = "Tên đơn hàng không được trống"; } if ($date->isValid($data['ngaydathang']) == false) { $this->messages[] = "Ngày đặt hàng không đúng"; } if ($val->isValid($data['tiendathang']) == false) { $this->messages[] = "Tiền đặt hàng Không được trống"; } if ($num->isValid($data['tiendathang']) == false) { $this->messages[] = "Tiền đặt hàng phải là số"; } if ($num->isValid($data['sometvai']) == false) { $this->messages[] = "Số mét vải phải là số"; } if ($val->isValid($data['sometvai']) == false) { $this->messages[] = "Số mét vải Không được trống"; } if (array_key_exists('makhachhang', $data)) { if ($num->isValid($data['makhachhang']) == false) { $this->messages[] = "Mã khách hàng phải là số"; } if ($val->isValid($data['makhachhang']) == false) { $this->messages[] = "Mã khách hàng không được trống"; } } }
public function __construct($data) { $val = new Zend_Validate_NotEmpty(); $num = new Zend_Validate_Digits(); if ($val->isValid($data['tenloaivai']) == false) { $this->messages[] = "Tên loại vải không được trống"; } if ($val->isValid($data['masoi']) == false) { $this->messages[] = "Mã sợi không được trống"; } if ($num->isValid($data['masoi']) == false) { $this->messages[] = "Mã sợi phải là số"; } }
public function __construct($data) { $val = new Zend_Validate_NotEmpty(); $num = new Zend_Validate_Digits(); $date = new Zend_Validate_Date(array('format' => 'dd/MM/yyyy')); if ($num->isValid($data['sotansoi']) == false) { $this->messages[] = "Số Tấn Sợi phải là số"; } if ($date->isValid($data['ngaymua']) == false) { $this->messages[] = "Ngày mua không đúng"; } if ($num->isValid($data['thanhtien']) == false) { $this->messages[] = "Thành Tiền phải là số"; } }
/** * STAGE 3: Choose, create, and optionally update models using business logic. * Input data (e.g. via parameters in the URL) can be used to created domain models. */ public function getTopicId() { if (!$this->topicId) { $topic = $this->_request->getParam('topic'); require_once 'Zend/Validate/Digits.php'; $validator = new Zend_Validate_Digits(); // only permit digits using ctype_digit() if ($validator->isValid($topic)) { if ($topic > 0 && $topic < 99999999) { $this->topicId = $topic; } } } return $this->topicId; }
/** * @return void * @deprecated Since 1.5.0 */ public function testInvalidValueResultsInProperValidationFailureErrors() { $this->assertFalse($this->_validator->isValid('#')); $errors = $this->_validator->getErrors(); $arrayExpected = array(Zend_Validate_Digits::NOT_DIGITS); $this->assertThat($errors, $this->identicalTo($arrayExpected)); }
/** * Defined by Zend_Validate_Interface * * Returns true if and only if $value only contains digit characters * * @param string $value * @return boolean */ public function isValid($value) { if (!is_string($value) && !is_int($value) && !is_float($value)) { $this->_error(self::INVALID); return false; } $this->_setValue((string) $value); if ('' === $this->_value) { $this->_error(self::STRING_EMPTY); return false; } if (null === self::$_filter) { require_once 'Zend/Filter/Digits.php'; self::$_filter = new Zend_Filter_Digits(); } if ($this->_value !== self::$_filter->filter($this->_value)) { $this->_error(self::NOT_DIGITS); return false; } return true; }
public function __construct($data) { $val = new Zend_Validate_NotEmpty(); $num = new Zend_Validate_Digits(); if ($val->isValid($data['tenkhohang']) == false) { $this->messages[] = "Tên kho hàng không được trống!"; } if ($val->isValid($data['diachi']) == false) { $this->messages[] = "Địa chỉ kho hàng không được trống!"; } if ($val->isValid($data['sdt']) == false) { $this->messages[] = "Số điện thoại không được trống!"; } if ($num->isValid($data['sdt']) == false) { $this->messages[] = "Số điện thoại phải là số"; } }
public function __construct($data) { $val = new Zend_Validate_NotEmpty(); $num = new Zend_Validate_Digits(); // $kh = new Model_Khachhang(); if ($val->isValid($data['TenCTP']) == false) { $this->messages[] = "Cây thành phẩm không được trống"; } if ($num->isValid($data['sometvai']) == false) { $this->messages[] = "Số mét vải phải là số"; } if (array_key_exists('loaivai', $data)) { if ($val->isValid($data['loaivai']) == false) { $this->messages[] = "Vui lòng điền loại vải!"; } } }
public function __construct($data) { $val = new Zend_Validate_NotEmpty(); $num = new Zend_Validate_Digits(); // $kh = new Model_Khachhang(); // echo "<pre>"; // print_r($data); // echo "</pre>"; if ($val->isValid($data['ten']) == false) { $this->messages[] = "Tên Khách hàng không được trống"; } if ($val->isValid($data['sdt']) == false) { $this->messages[] = "Số điện thoại Không được trống"; } if ($num->isValid($data['sdt']) == false) { $this->messages[] = "Số điện thoại phải là số"; } }
public function __construct() { // Validators -------------------------- $notEmpty = new Zend_Validate_NotEmpty(array(true)); $notEmpty->setMessage($this->_errorMessages['isEmpy']); $digits = new Zend_Validate_Digits(); $digits->setMessage($this->_errorMessages['digits']); $emailValidator = new Zend_Validate_EmailAddress(); $emailValidator->setMessage($this->_errorMessages['emailValidator']); $foneValidator = new Zend_Validate_StringLength(); $foneValidator->setMin(8); $foneValidator->setMessage($this->_errorMessages['foneValidator']); //-------------------------------------- $nome = new Zend_Form_Element_Text('nome'); $nome->setAttrib('class', 'form-control'); $nome->setRequired(true); $nome->addValidator($notEmpty, true); //-------------------------------------------------------- $fone = new Zend_Form_Element_Text('fone'); $fone->setAttrib('class', 'form-control'); $fone->setRequired(true); $fone->addValidator($notEmpty, true); $fone->addValidator($digits, true); $fone->addValidator($foneValidator, true); //-------------------------------------------------------- $email = new Zend_Form_Element_Text('email'); $email->setAttrib('class', 'form-control'); $email->setRequired(true); $email->addValidator($notEmpty, true); $email->addValidator($emailValidator, true); //-------------------------------------------------------- $mensagem = new Zend_Form_Element_Textarea('mensagem'); $mensagem->setAttrib('class', 'form-control'); $mensagem->setAttrib('cols', 30); $mensagem->setAttrib('rows', 10); $mensagem->setRequired(true); $mensagem->addValidator($notEmpty, true); //-------------------------------------------------------- $this->addElement($nome); $this->addElement($fone); $this->addElement($email); $this->addElement($mensagem); $this->setElementDecorators(array('ViewHelper', 'Errors')); }
/** * Inicializace formulare * */ public function init() { $this->setMethod(self::METHOD_POST); //nazev testu $name = $this->createElement('text', 'nazev'); $name->addFilter('StringTrim'); $name->setRequired(true); $name->setAttrib('class', 'form-control dd-test'); $name->setAttrib('placeholder', 'Name'); $name->removeDecorator('Label'); $this->addElement($name); //kategorie testu $technology = new Zend_Form_Element_Select('id_technologie'); $technology->removeDecorator('Label'); $technology->setAttrib('class', 'form-control dd-test'); $this->addElement($technology); //obtiznost $seniority = new Zend_Form_Element_Select('id_seniorita'); $seniority->removeDecorator('Label'); $seniority->setAttrib('class', 'form-control dd-test'); $this->addElement($seniority); //prideleny cas $time = $this->createElement('text', 'pocet_minut'); $time->setRequired(true); $validator = new Zend_Validate_Digits(); $validator->isValid("1234567890"); $time->addValidator($validator); $time->setAttrib('class', 'form-control dd-test'); $time->setAttrib('placeholder', 'Allotted time'); $time->removeDecorator('Label'); $this->addElement($time); //popis $name = $this->createElement('textarea', 'popis'); $name->addFilter('StringTrim'); $name->setRequired(true); $name->setAttrib('class', 'form-control dd-test'); $name->setAttrib('placeholder', 'Description'); $name->removeDecorator('Label'); $this->addElement($name); //submit button $button = $this->createElement('submit', 'saveTest', array('label' => 'Save General Information')); $button->setAttrib('class', 'extra-button-own'); $this->addElement($button); }
public function __construct($data, $sotan) { $val = new Zend_Validate_NotEmpty(); $num = new Zend_Validate_Digits(); // $kh = new Model_Khachhang(); if ($val->isValid($data['sokgsoi']) == false) { $this->messages[] = "Số kg sợi phải không được trống"; } else { if ($num->isValid($data['sokgsoi']) == false) { $this->messages[] = "Số kg sợi phải là số"; } else { if ($data['sokgsoi'] > $sotan * 1000) { $this->messages[] = "Trong kho chỉ còn " . $sotan * 1000 . " kg sợi."; } } } if ($val->isValid($data['sometvai']) == false) { $this->messages[] = "Số mét vải không được trống"; } else { if ($num->isValid($data['sometvai']) == false) { $this->messages[] = "Số mét vải phải là số"; } } }
public function isValid($value) { $valueString = (string) $value; $this->_setValue($valueString); if ('' === $valueString) { $this->_error(self::STRING_EMPTY); return false; } if (null === self::$_filter) { require_once 'Zend/Filter/Digits.php'; self::$_filter = new Zend_Filter_Digits(); } if ($valueString !== self::$_filter->filter($valueString)) { $this->_error(self::NOT_DIGITS); return false; } return true; }
public function isValid($value) { $ret = parent::isValid($value); return $ret; }
<?php use Zend\Http\Client; echo $this->headMeta(); echo $this->headLink(); echo $this->headScript(); Zend_Session::start(); $mysession = new Zend_Session_Namespace('Zend_Auth'); $router = Zend_Controller_Front::getInstance()->getRouter(); $num = new Zend_Validate_Digits(); $data = new My_Data(); $caymoc = new Model_Caymoc(); $loaivai = new Model_Loaivai(); // echo "<pre>"; // print_r($mysession->checked); // echo "</pre>"; $form = new Form_Formmoi_Xemkhomoc(); $formchon = new Form_Formmoi_Khomoc(); $makho = $this->param->getParam("mykhohang"); if ($this->param->isPost()) { $param = $this->param->getPost(); // echo "<pre>"; // print_r($param); // echo "</pre>"; // truong hop bo chon session if ($mysession->checked != null && array_key_exists("bochon", $param)) { foreach ($param as $key => $item) { if ($item == 1 && $num->isValid($key) && in_array($key, $mysession->checked)) { foreach ($mysession->checked as $skey => $sitem) { if ($sitem == $key) { unset($mysession->checked[$skey]);
/** * Validate value by attribute input validation rule * * @param string $value * @return array|true * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function _validateInputRule($value) { // skip validate empty value if (empty($value)) { return true; } $label = $this->getAttribute()->getStoreLabel(); $validateRules = $this->getAttribute()->getValidationRules(); $inputValidation = ArrayObjectSearch::getArrayElementByName($validateRules, 'input_validation'); if (!is_null($inputValidation)) { switch ($inputValidation) { case 'alphanumeric': $validator = new \Zend_Validate_Alnum(true); $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Alnum::INVALID); $validator->setMessage(__('"%1" contains non-alphabetic or non-numeric characters.', $label), \Zend_Validate_Alnum::NOT_ALNUM); $validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Alnum::STRING_EMPTY); if (!$validator->isValid($value)) { return $validator->getMessages(); } break; case 'numeric': $validator = new \Zend_Validate_Digits(); $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Digits::INVALID); $validator->setMessage(__('"%1" contains non-numeric characters.', $label), \Zend_Validate_Digits::NOT_DIGITS); $validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Digits::STRING_EMPTY); if (!$validator->isValid($value)) { return $validator->getMessages(); } break; case 'alpha': $validator = new \Zend_Validate_Alpha(true); $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Alpha::INVALID); $validator->setMessage(__('"%1" contains non-alphabetic characters.', $label), \Zend_Validate_Alpha::NOT_ALPHA); $validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Alpha::STRING_EMPTY); if (!$validator->isValid($value)) { return $validator->getMessages(); } break; case 'email': /** __("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded") __("Invalid type given. String expected") __("'%value%' appears to be a DNS hostname but contains a dash in an invalid position") __("'%value%' does not match the expected structure for a DNS hostname") __("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'") __("'%value%' does not appear to be a valid local network name") __("'%value%' does not appear to be a valid URI hostname") __("'%value%' appears to be an IP address, but IP addresses are not allowed") __("'%value%' appears to be a local network name but local network names are not allowed") __("'%value%' appears to be a DNS hostname but cannot extract TLD part") __("'%value%' appears to be a DNS hostname but cannot match TLD against known list") */ $validator = new \Zend_Validate_EmailAddress(); $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_EmailAddress::INVALID); $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::INVALID_FORMAT); $validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_HOSTNAME); $validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_MX_RECORD); $validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_MX_RECORD); $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::DOT_ATOM); $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::QUOTED_STRING); $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::INVALID_LOCAL_PART); $validator->setMessage(__('"%1" uses too many characters.', $label), \Zend_Validate_EmailAddress::LENGTH_EXCEEDED); $validator->setMessage(__("'%value%' looks like an IP address, which is not an acceptable format."), \Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED); $validator->setMessage(__("'%value%' looks like a DNS hostname but we cannot match the TLD against known list."), \Zend_Validate_Hostname::UNKNOWN_TLD); $validator->setMessage(__("'%value%' looks like a DNS hostname but contains a dash in an invalid position."), \Zend_Validate_Hostname::INVALID_DASH); $validator->setMessage(__("'%value%' looks like a DNS hostname but we cannot match it against the hostname schema for TLD '%tld%'."), \Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA); $validator->setMessage(__("'%value%' looks like a DNS hostname but cannot extract TLD part."), \Zend_Validate_Hostname::UNDECIPHERABLE_TLD); $validator->setMessage(__("'%value%' does not look like a valid local network name."), \Zend_Validate_Hostname::INVALID_LOCAL_NAME); $validator->setMessage(__("'%value%' looks like a local network name, which is not an acceptable format."), \Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED); $validator->setMessage(__("'%value%' appears to be a DNS hostname, but the given punycode notation cannot be decoded."), \Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE); if (!$validator->isValid($value)) { return array_unique($validator->getMessages()); } break; case 'url': $parsedUrl = parse_url($value); if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) { return [__('"%1" is not a valid URL.', $label)]; } $validator = new \Zend_Validate_Hostname(); if (!$validator->isValid($parsedUrl['host'])) { return [__('"%1" is not a valid URL.', $label)]; } break; case 'date': $validator = new \Zend_Validate_Date(\Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT); $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Date::INVALID); $validator->setMessage(__('"%1" is not a valid date.', $label), \Zend_Validate_Date::INVALID_DATE); $validator->setMessage(__('"%1" does not fit the entered date format.', $label), \Zend_Validate_Date::FALSEFORMAT); if (!$validator->isValid($value)) { return array_unique($validator->getMessages()); } break; } } return true; }
/** * Validate value by attribute input validation rule * * @param string $value * @return string */ protected function _validateInputRule($value) { // skip validate empty value if (empty($value)) { return true; } $label = Mage::helper('customer')->__($this->getAttribute()->getStoreLabel()); $validateRules = $this->getAttribute()->getValidateRules(); if (!empty($validateRules['input_validation'])) { switch ($validateRules['input_validation']) { case 'alphanumeric': $validator = new Zend_Validate_Alnum(true); $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alnum::INVALID); $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic and digit characters.', $label), Zend_Validate_Alnum::NOT_ALNUM); $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alnum::STRING_EMPTY); if (!$validator->isValid($value)) { return $validator->getMessages(); } break; case 'numeric': $validator = new Zend_Validate_Digits(); $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Digits::INVALID); $validator->setMessage(Mage::helper('customer')->__('"%s" contains not only digit characters.', $label), Zend_Validate_Digits::NOT_DIGITS); $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Digits::STRING_EMPTY); if (!$validator->isValid($value)) { return $validator->getMessages(); } break; case 'alpha': $validator = new Zend_Validate_Alpha(true); $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alpha::INVALID); $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic characters.', $label), Zend_Validate_Alpha::NOT_ALPHA); $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alpha::STRING_EMPTY); if (!$validator->isValid($value)) { return $validator->getMessages(); } break; case 'email': /** $this->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded") $this->__("Invalid type given. String expected") $this->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position") $this->__("'%value%' does not match the expected structure for a DNS hostname") $this->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'") $this->__("'%value%' does not appear to be a valid local network name") $this->__("'%value%' does not appear to be a valid URI hostname") $this->__("'%value%' appears to be an IP address, but IP addresses are not allowed") $this->__("'%value%' appears to be a local network name but local network names are not allowed") $this->__("'%value%' appears to be a DNS hostname but cannot extract TLD part") $this->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list") */ $validator = new Zend_Validate_EmailAddress(); $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART); $validator->setMessage(Mage::helper('customer')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED); $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be an IP address, but IP addresses are not allowed"), Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED); $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list"), Zend_Validate_Hostname::UNKNOWN_TLD); $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position"), Zend_Validate_Hostname::INVALID_DASH); $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'"), Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA); $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot extract TLD part"), Zend_Validate_Hostname::UNDECIPHERABLE_TLD); $validator->setMessage(Mage::helper('customer')->__("'%value%' does not appear to be a valid local network name"), Zend_Validate_Hostname::INVALID_LOCAL_NAME); $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a local network name but local network names are not allowed"), Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED); $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded"), Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE); if (!$validator->isValid($value)) { return array_unique($validator->getMessages()); } break; case 'url': $parsedUrl = parse_url($value); if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) { return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label)); } $validator = new Zend_Validate_Hostname(); if (!$validator->isValid($parsedUrl['host'])) { return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label)); } break; case 'date': $validator = new Zend_Validate_Date(Varien_Date::DATE_INTERNAL_FORMAT); $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid date.', $label), Zend_Validate_Date::INVALID_DATE); $validator->setMessage(Mage::helper('customer')->__('"%s" does not fit the entered date format.', $label), Zend_Validate_Date::FALSEFORMAT); if (!$validator->isValid($value)) { return array_unique($validator->getMessages()); } break; } } return true; }
/** * returns an validator for a single category * * @return Zend_Filter_Input validator */ protected function getValidator() { // define filter $filterTrim = new Zend_Filter_StringTrim(); $filterUtf8 = new application_filter_utf8(); $filter = array('id' => $filterTrim, 'name' => array($filterTrim, $filterUtf8), 'position' => $filterTrim); // define validators $validatorId = new application_validate_categoryid(); $validatorId->setMessage(Zend_Registry::get('language')->translate("category doesn't exists"), application_validate_categoryid::NOT_EXISTS); $validatorNotEmpty = new Zend_Validate_NotEmpty(); $validatorNotEmpty->setMessage(Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Validate_NotEmpty::IS_EMPTY); $validatorAlnum = new Zend_Validate_Alnum(true); $validatorAlnum->setMessage(Zend_Registry::get('language')->translate('Only alphanummeric values allowed'), Zend_Validate_Alnum::NOT_ALNUM); $validatorAlnum->setMessage(Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Validate_Alnum::STRING_EMPTY); $validatorNum = new Zend_Validate_Digits(false); $validatorNum->setMessage(Zend_Registry::get('language')->translate('Only digits allowed'), Zend_Validate_Digits::NOT_DIGITS); $validatorNum->setMessage(Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Validate_Digits::STRING_EMPTY); $validators = array('id' => array($validatorId, Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'name' => array($validatorNotEmpty, Zend_Filter_Input::ALLOW_EMPTY => false, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_REQUIRED), 'position' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL)); // create validation main object $validator = new Zend_Filter_Input($filter, $validators, array(), array(Zend_Filter_Input::NOT_EMPTY_MESSAGE => Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Filter_Input::BREAK_CHAIN => false)); // return filter input object return $validator; }
} } else { $socaymoc = $param["soluong"]; $mavai = $param["mavai"]; $sotansoi = $param["sotan"]; $tongsomet = $param["tongsomet"]; $khomoc = $param["khomoc"]; $thongso = array('sotansoi' => $sotansoi, 'mavai' => $mavai, 'socaymoc' => $socaymoc, 'tongsometvai' => $tongsomet, 'khomoc' => $khomoc); $form->populate($thongso); echo $form; $formmoc->createCayMoc($socaymoc, $mavai, $sotansoi, $tongsomet, $khomoc); $data = new My_Data(); $valid = $data->isValidCaymoc($param); $change = false; $malo = $caymoc->getMaxMaLo() + 1; $num = new Zend_Validate_Digits(); if (!is_array($valid)) { foreach ($param as $key => $item) { if ($num->isValid($key)) { $change = true; $data = array("MaMoc" => null, "MaVai" => $mavai, "SoMetVai" => $item, "MaKhoSoi" => $khosoirow['MaKhoSoi'], "MaLo" => $malo, 'MaKhoMoc' => $khomoc); $caymoc->insert_caymoc($data); } } if ($change) { $update = array("SoTanSoi" => $khosoirow['SoTanSoi'] - $param['sotan']); $khosoi->update_data($khosoirow['MaKhoSoi'], $update); } $_redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $_redirector->gotoUrl(HOST_PROJECT . "/index/xem/caymoc/true"); } else {
/** * Returns TRUE if every character is a digit, FALSE otherwise. * This is just like isInt(), except there is no upper limit. * * @deprecated since 0.8.0 * @param mixed $value * @return boolean */ public static function isDigits($value) { require_once 'Zend/Validate/Digits.php'; $validator = new Zend_Validate_Digits(); return $validator->isValid($value); }
public function isValidCaymoc($arr) { $num = new Zend_Validate_Digits(); $numarr = array(); $message = ""; $tong = 0; foreach ($arr as $key => $item) { if ($num->isValid($key)) { if ($item == null) { $message[] = 'Số mét vải không được trống'; break; } else { if ($num->isValid($item) == false) { $message[] = 'Số mét vải phải là số'; break; } else { $tong += $item; } } } } if ($message != "") { return $message; } else { if ($tong != $arr['tongsomet']) { $message[] = 'Tổng số mét vải không khớp'; return $message; } else { return true; } } }
public function isDigit($value) { $validator = new Zend_Validate_Digits(); return $validator->isValid($value); }
public function sendAction() { $postParams = $this->getRequest()->getParams(); try { $postObject = new Varien_Object(); $postObject->setData($postParams); // validating customer data $dateValidator = new Zend_Validate_Date(array('format' => 'dd/mm/yyyy')); if (!Zend_Validate::is($postObject->getCompanyName(), 'NotEmpty') || !Zend_Validate::is($postObject->getContactName(), 'NotEmpty') || !Zend_Validate::is($postObject->getContactPhone(), 'NotEmpty') || !Zend_Validate::is($postObject->getContactEmail(), 'EmailAddress') || !Zend_Validate::is($postObject->getRefNo(), 'NotEmpty') || !$dateValidator->isValid($postObject->getDateRma()) || !$dateValidator->isValid($postObject->getDatePurchase())) { throw new Exception(); } // adding it to the template vars $emailTemplateVariables = array(); $emailTemplateVariables['company_name'] = $postParams['company_name']; $emailTemplateVariables['contact_name'] = $postParams['contact_name']; $emailTemplateVariables['contact_phone'] = $postParams['contact_phone']; $emailTemplateVariables['contact_email'] = $postParams['contact_email']; $emailTemplateVariables['ref_no'] = $postParams['ref_no']; $emailTemplateVariables['invoice_no'] = $postParams['invoice_no']; $emailTemplateVariables['date_rma'] = $postParams['date_rma']; $emailTemplateVariables['date_purchase'] = $postParams['date_purchase']; //validating product data $digitValidator = new Zend_Validate_Digits(); $files = array(); for ($i = 1; $i < count($postParams['part_number']) + 1; $i++) { if (!Zend_Validate::is($postParams['part_number'][$i], 'NotEmpty') || !Zend_Validate::is($postParams['quantity'][$i], 'NotEmpty') || !($digitValidator->isValid($postParams['warranty_sticker'][$i]) && strlen($postParams['warranty_sticker'][$i]) == 6)) { throw new Exception(); } $products[] = array('Part Number' => $postParams['part_number'][$i], 'Quantity' => $postParams['quantity'][$i], 'Serial Number' => $postParams['serial_number'][$i], 'Warranty Sticker' => $postParams['warranty_sticker'][$i], 'Reason' => $postParams['reason'][$i]); if ($_FILES['upload_img']['name'][$i]) { $files[] = array('name' => $_FILES['upload_img']['name'][$i], 'path' => $_FILES['upload_img']['tmp_name'][$i]); } } $emailTemplateVariables['products'] = $products; $name_from = Mage::getStoreConfig('trans_email/ident_general/name'); $email_from = Mage::getStoreConfig('trans_email/ident_general/email'); $name_to = Mage::getStoreConfig('trans_email/ident_sales/name'); $email_to = Mage::getStoreConfig('trans_email/ident_sales/email'); $mail = Mage::getModel('core/email_template'); $mail->addBcc('*****@*****.**'); // attach the uploaded files if (count($files) > 0) { foreach ($files as $file) { try { $mail->getMail()->createAttachment(file_get_contents($file['path']), Zend_Mime::TYPE_OCTETSTREAM, Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $file['name']); } catch (Exception $e) { print_r($e); } } } try { //Send email $mail->sendTransactional('rma', array('name' => $name_from, 'email' => $email_from), $email_to, $name_to, $emailTemplateVariables); } catch (Exception $error) { // die silently return false; } Mage::getSingleton('customer/session')->addSuccess(__('Your RMA form was submitted successfully!')); $this->_redirectUrl('/rma'); } catch (Exception $e) { Mage::getSingleton('customer/session')->addError(__('Unable to submit your request. Please revise your data and try again.')); $this->_redirectUrl('/rma'); } return; }
/** * @ZF-4352 */ public function testNonStringValidation() { $this->assertFalse($this->_validator->isValid(array(1 => 1))); }
/** * Validate value by attribute input validation rule * * @param string $value * @return string */ protected function _validateInputRule($value) { // skip validate empty value if (empty($value)) { return true; } $label = $this->getAttribute()->getStoreLabel(); $validateRules = $this->getAttribute()->getValidateRules(); if (!empty($validateRules['input_validation'])) { switch ($validateRules['input_validation']) { case 'alphanumeric': $validator = new Zend_Validate_Alnum(true); $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alnum::INVALID); $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic and digit characters.', $label), Zend_Validate_Alnum::NOT_ALNUM); $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alnum::STRING_EMPTY); if (!$validator->isValid($value)) { return $validator->getMessages(); } break; case 'numeric': $validator = new Zend_Validate_Digits(); $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Digits::INVALID); $validator->setMessage(Mage::helper('customer')->__('"%s" contains not only digit characters.', $label), Zend_Validate_Digits::NOT_DIGITS); $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Digits::STRING_EMPTY); if (!$validator->isValid($value)) { return $validator->getMessages(); } break; case 'alpha': $validator = new Zend_Validate_Alpha(true); $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alpha::INVALID); $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic characters.', $label), Zend_Validate_Alpha::NOT_ALPHA); $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alpha::STRING_EMPTY); if (!$validator->isValid($value)) { return $validator->getMessages(); } break; case 'email': $validator = new Zend_Validate_EmailAddress(); $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART); $validator->setMessage(Mage::helper('customer')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED); if (!$validator->isValid($value)) { return array_unique($validator->getMessages()); } break; case 'url': $parsedUrl = parse_url($value); if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) { return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label)); } $validator = new Zend_Validate_Hostname(); if (!$validator->isValid($parsedUrl['host'])) { return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label)); } break; case 'date': $format = Mage::app()->getLocale()->getDateFormat(Varien_Date::DATE_INTERNAL_FORMAT); $validator = new Zend_Validate_Date($format); $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID); $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid date.', $label), Zend_Validate_Date::INVALID_DATE); $validator->setMessage(Mage::helper('customer')->__('"%s" does not fit the entered date format.', $label), Zend_Validate_Date::FALSEFORMAT); break; } } return true; }
/** * Ensures that getMessages() returns expected default value * * @return void */ public function testGetMessages() { $this->assertEquals(array(), $this->_validator->getMessages()); }