本文整理汇总了PHP中Zend_Validate_Int::setMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Validate_Int::setMessage方法的具体用法?PHP Zend_Validate_Int::setMessage怎么用?PHP Zend_Validate_Int::setMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Validate_Int
的用法示例。
在下文中一共展示了Zend_Validate_Int::setMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init()
{
parent::init();
if (is_null($this->getAttrib('size'))) {
$this->setAttrib('size', 6);
}
$validator = new Zend_Validate_Int();
$validator->setMessage('validation_error_int');
$this->addValidator($validator);
$options = array();
$min = $this->getAttrib('min');
if (is_null($min)) {
$min = 0;
} else {
$this->setAttrib('min', null);
// remove from rendered attributes
}
$options['min'] = $min;
$max = $this->getAttrib('max');
if (is_null($max)) {
$validator = new Zend_Validate_GreaterThan(array('min' => $min - 1));
// inclusive not supported in ZF1
$validator->setMessage('validation_error_number_tooSmall');
} else {
$this->setAttrib('max', null);
// remove from rendered attributes
$options['max'] = $max;
$validator = new Zend_Validate_Between(array('min' => $min, 'max' => $max));
$validator->setMessage('validation_error_number_notBetween');
}
$this->addValidator($validator);
}
示例2: init
public function init()
{
parent::init();
if (is_null($this->getAttrib('size'))) {
$this->setAttrib('size', 6);
}
$validator = new Zend_Validate_Int();
$validator->setMessage('validation_error_int');
$this->addValidator($validator);
$validator = new Zend_Validate_GreaterThan(-1);
$validator->setMessage('validation_error_negative_number');
$this->addValidator($validator);
}
示例3: init
public function init()
{
parent::init();
$this->setRequired(true);
$this->setDisableTranslator(true);
// publishing institutions are not translated
$validator = new Zend_Validate_Int();
$validator->setMessage('validation_error_int');
$this->addValidator($validator);
$options = Opus_DnbInstitute::getPublishers();
foreach ($options as $option) {
$this->addMultiOption($option->getId(), $option->getDisplayName());
}
}
示例4: init
public function init()
{
parent::init();
$this->setRequired(true);
$this->setDisableTranslator(true);
// Schriftenreihen werden nicht übersetzt
$validator = new Zend_Validate_Int();
$validator->setMessage('validation_error_int');
$this->addValidator($validator);
$options = Opus_Series::getAll();
foreach ($options as $option) {
$this->addMultiOption($option->getId(), $option->getTitle());
}
}
示例5: init
public function init()
{
parent::init();
$this->setLabel($this->getName());
// TODO use prefix for translation
$validators = array();
$validator = new Zend_Validate_Int();
$validator->setMessage('validation_error_year_invalid_format');
$validators[] = $validator;
$validator = new Zend_Validate_GreaterThan(-1);
$validator->setMessages(array(Zend_Validate_GreaterThan::NOT_GREATER => 'validation_error_year_invalid_negative'));
$validators[] = $validator;
$validator = new Zend_Validate_LessThan(10000);
$validator->setMessages(array(Zend_Validate_LessThan::NOT_LESS => 'validation_error_year_too_large'));
$validators[] = $validator;
$this->setAttrib('placeholder', $this->getTranslator()->translate('year_format'));
$this->setAttrib('size', 6);
$this->setAttrib('maxlength', 4);
$this->setValidators($validators, true);
}
示例6: formValidator
public function formValidator($form,$formType)
{
$numberValidator = new Zend_Validate_Int();
$numberValidator->setMessage(General_Models_Text::$text_notInt);
$form->getElement('mileEarly')->addValidator($numberValidator);
$form->getElement('mileEnd')->addValidator($numberValidator);
$emptyValidator = new Zend_Validate_NotEmpty();
$emptyValidator->setMessage(General_Models_Text::$text_notEmpty);
$form->getElement('mileEarly')->setAllowEmpty(false)
->addValidator($emptyValidator);
$form->getElement('mileEnd')->setAllowEmpty(false)
->addValidator($emptyValidator);
return $form;
}
示例7: parseInt
/**
* Faz o parse de um elemento <int> para Zend_Form.
* @param SimpleXMLElement $element
*/
protected function parseInt($element)
{
$form_element = new Zend_Form_Element_Text((string) $element->id);
$validate_ìnt = new Zend_Validate_Int();
$validate_ìnt->setMessage("Somente números inteiros");
$form_element->addValidator($validate_ìnt);
$form_element->setLabel((string) $element->label);
$form_element->setAttrib('size', $element->size);
if (isset($element->unit)) {
$form_element->setDescription($element->unit);
}
if (isset($element->value)) {
$form_element->setValue($element->value);
} else {
if (isset($element->default)) {
$form_element->setValue($element->default);
}
}
return $form_element;
}
示例8: formValidator
public function formValidator($form,$formType)
{
$numberValidator = new Zend_Validate_Float();
$numberValidator->setMessage(General_Models_Text::$text_notInt);
$form->getElement('amount')->addValidator($numberValidator);
$intValidator = new Zend_Validate_Int();
$intValidator->setMessage(General_Models_Text::$text_notInt);
$form->getElement('level')->addValidator($intValidator);
$form->getElement('period')->addValidator($intValidator);
$form->getElement('constrArea')->addValidator($intValidator);
$emptyValidator = new Zend_Validate_NotEmpty();
$emptyValidator->setMessage(General_Models_Text::$text_notEmpty);
$form->getElement('name')->setAllowEmpty(false)
->addValidator($emptyValidator);
$form->getElement('contactName')->setAllowEmpty(false)
->addValidator($emptyValidator);
$form->getElement('license')->setAllowEmpty(false)
->addValidator($emptyValidator);
$form->getElement('startDate')->setAllowEmpty(false)
->addValidator($emptyValidator);
$dateValidator = new Zend_Validate_Date();
$dateValidator->setMessage(General_Models_Text::$text_notDate);
$form->getElement('startDate')->addValidator($dateValidator);
return $form;
}
示例9: validate
/**
* returns an validator for settings params or error array
*
* @return Zend_Filter_Input|array on success data on error message array
* @param array $data current data for validation
*/
public function validate($data)
{
// define filter
$filterTrim = new Zend_Filter_StringTrim();
$filter = array('deleteItems' => $filterTrim, 'imagesPosition' => $filterTrim, 'imagesHeight' => $filterTrim, 'language' => $filterTrim, 'refresh' => $filterTrim, 'lastrefresh' => $filterTrim, 'view' => $filterTrim, 'offset' => $filterTrim, 'itemsperpage' => $filterTrim, 'selected' => $filterTrim, 'dateFilter' => $filterTrim, 'dateStart' => $filterTrim, 'dateEnd' => $filterTrim, 'search' => $filterTrim, 'unread' => $filterTrim, 'starred' => $filterTrim, 'currentPriorityStart' => $filterTrim, 'currentPriorityEnd' => $filterTrim, 'saveOpenCategories' => $filterTrim, 'openCategories' => $filterTrim, 'firstUnread' => $filterTrim, 'newWindow' => $filterTrim, 'public' => $filterTrim, 'anonymizer' => $filterTrim, 'sort' => $filterTrim, 'openitems' => $filterTrim, 'iconcache' => $filterTrim);
// define validators
$validatorType = new Zend_Validate_InArray(array("both", "multimedia", "messages"));
$validatorType->setMessage(Zend_Registry::get('language')->translate('Only both, multimedia, message allowed'), Zend_Validate_InArray::NOT_IN_ARRAY);
$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);
$validatorNum = new Zend_Validate_Int(Zend_Registry::get('session')->language);
$validatorNum->setLocale(Zend_Registry::get('session')->language);
$validatorNum->setMessage(Zend_Registry::get('language')->translate('Only digits allowed'), Zend_Validate_Int::NOT_INT);
$validatorInArray = new Zend_Validate_InArray(array("top", "bottom"));
$validatorInArray->setMessage(Zend_Registry::get('language')->translate('Only top or bottom allowed'), Zend_Validate_InArray::NOT_IN_ARRAY);
$validatorLanguage = new Zend_Validate_InArray(Zend_Registry::get('language')->getList());
$validatorLanguage->setMessage(Zend_Registry::get('language')->translate('Language is not available'), Zend_Validate_InArray::NOT_IN_ARRAY);
$validatorDate = new Zend_Validate_Date();
$validatorDate->setMessage(Zend_Registry::get('language')->translate('No valid date given'), Zend_Validate_Date::INVALID);
$validatorDate->setMessage(Zend_Registry::get('language')->translate('No valid date given'), Zend_Validate_Date::FALSEFORMAT);
$validatorBiggerThanZero = new Zend_Validate_GreaterThan(0);
$validatorBiggerThanZero->setMessage(Zend_Registry::get('language')->translate('Value must be bigger than 0'), Zend_Validate_GreaterThan::NOT_GREATER);
$validatorBetweenDays = new Zend_Validate_Between(0, 2000);
$validatorBetweenDays->setMessage(Zend_Registry::get('language')->translate('Please choose a value between 0 and 2000 days'), Zend_Validate_Between::NOT_BETWEEN);
$validatorBetweenItemsperpage = new Zend_Validate_Between(0, 200);
$validatorBetweenItemsperpage->setMessage(Zend_Registry::get('language')->translate('Please choose a value between 0 and 200 items per page'), Zend_Validate_Between::NOT_BETWEEN);
$validatorSort = new Zend_Validate_InArray(array("date", "dateasc", "priority", "priorityasc"));
$validatorSort->setMessage(Zend_Registry::get('language')->translate('Only date or rating allowed'), Zend_Validate_InArray::NOT_IN_ARRAY);
$validators = array('deleteItems' => array($validatorNum, $validatorBetweenDays, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'imagesPosition' => array($validatorInArray, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'language' => array($validatorLanguage, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'refresh' => array($validatorNum, $validatorBiggerThanZero, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'lastrefresh' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'view' => array($validatorType, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'offset' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'itemsperpage' => array($validatorNum, $validatorBetweenItemsperpage, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'selected' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'dateFilter' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'search' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'unread' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'starred' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'currentPriorityStart' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'currentPriorityEnd' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'saveOpenCategories' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'openCategories' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'firstUnread' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'newWindow' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'public' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'anonymizer' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'sort' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL, $validatorSort), 'openitems' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'iconcache' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL));
// optional check date
if (isset($data['dateFilter']) && $data['dateFilter'] == 1) {
$validators['dateStart'] = $validatorDate;
$validators['dateEnd'] = $validatorDate;
} else {
$validators['dateStart'] = array(Zend_Filter_Input::ALLOW_EMPTY => true);
$validators['dateEnd'] = array(Zend_Filter_Input::ALLOW_EMPTY => true);
$data['dateStart'] = '';
$data['dateEnd'] = '';
}
// create validation main object
$validator = new Zend_Filter_Input($filter, $validators, $data, 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 parent::validate($validator);
}
示例10: formValidator
public function formValidator($form,$formType)
{
$emptyValidator = new Zend_Validate_NotEmpty();
$emptyValidator->setMessage(General_Models_Text::$text_notEmpty);
$form->getElement('logDate')->setAllowEmpty(false)
->addValidator($emptyValidator);
$form->getElement('part')->setAllowEmpty(false)
->addValidator($emptyValidator);
$form->getElement('operator')->setAllowEmpty(false)
->addValidator($emptyValidator);
$form->getElement('foreman')->setAllowEmpty(false)
->addValidator($emptyValidator);
$dateValidator = new Zend_Validate_Date();
$dateValidator->setMessage(General_Models_Text::$text_notDate);
$form->getElement('logDate')->addValidator($dateValidator);
$intValidator = new Zend_Validate_Int();
$intValidator->setMessage(General_Models_Text::$text_notInt);
$form->getElement('number')->addValidator($intValidator);
$form->getElement('tempHi')->addValidator($intValidator);
$form->getElement('tempLo')->addValidator($intValidator);
return $form;
}
示例11: _createIntValidator
protected function _createIntValidator($errorMessage)
{
$intValidator = new Zend_Validate_Int();
$intValidator->setMessage($errorMessage, Zend_Validate_Int::NOT_INT);
return $intValidator;
}
示例12: validate
/**
* validates feed input
*
* @return Zend_Filter_Input|array validator or error message array
* @param array $data for validating
* @param int $validateid (optional) indicates whether id has to be validated
*/
protected function validate($data, $validateId = false)
{
// define filter
$filterTrim = new Zend_Filter_StringTrim();
$filter = array('name' => $filterTrim, 'url' => $filterTrim, 'category' => $filterTrim, 'priority' => $filterTrim, 'favicon' => $filterTrim, 'filter' => $filterTrim, 'source' => $filterTrim);
if (!isset($data['source'])) {
$data['source'] = '';
}
// define validators
$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);
$validatorCategoryId = new application_validate_categoryid();
$validatorCategoryId->setMessage(Zend_Registry::get('language')->translate("category doesn't exists"), application_validate_categoryid::NOT_EXISTS);
$validatorSource = new application_validate_source();
$validatorSource->setMessage(Zend_Registry::get('language')->translate("source doesn't exists"), application_validate_source::NOT_EXISTS);
$validatorNum = new Zend_Validate_Int(Zend_Registry::get('session')->language);
$validatorNum->setLocale(Zend_Registry::get('session')->language);
$validatorNum->setMessage(Zend_Registry::get('language')->translate('Only digits allowed'), Zend_Validate_Int::NOT_INT);
$validatorNum->setMessage(Zend_Registry::get('language')->translate('Only digits allowed'), Zend_Validate_Int::INVALID);
$validatorDuplicateFeed = new application_validate_duplicatefeed($data['source'], $validateId ? $data['id'] : false);
$validatorDuplicateFeed->setMessage(Zend_Registry::get('language')->translate("feed already exists"), application_validate_duplicatefeed::ALREADY_EXISTS);
$validators = array('name' => array($validatorNotEmpty, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_REQUIRED), 'url' => array($validatorDuplicateFeed, Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'category' => array($validatorNum, $validatorCategoryId, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'priority' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_REQUIRED), 'favicon' => array(Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL, Zend_Filter_Input::ALLOW_EMPTY => true), 'filter' => array(Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL, Zend_Filter_Input::ALLOW_EMPTY => true), 'source' => array($validatorNotEmpty, $validatorSource, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_REQUIRED));
// read from source whether url is optional or not
if ($validatorSource->isValid($data['source'])) {
$plugin = Zend_Controller_Action_HelperBroker::getStaticHelper('pluginloader')->getPlugin($data['source']);
if (!$plugin->sourceOptional && $plugin->source !== false) {
$validators['url'] = array($validatorNotEmpty, $validatorDuplicateFeed, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_REQUIRED);
}
}
// insert filter and validate rules for id
if ($validateId !== false) {
$validatorFeedId = new application_validate_feedid();
$validatorFeedId->setMessage(Zend_Registry::get('language')->translate("feed doesn't exists"), application_validate_feedid::NOT_EXISTS);
$filter['id'] = $filterTrim;
$validators['id'] = array($validatorNum, $validatorFeedId, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_REQUIRED);
}
// create validation main object
$validator = new Zend_Filter_Input($filter, $validators, $data, 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 parent::validate($validator);
}
示例13: _validateInteger
private function _validateInteger()
{
$validators = array();
$validator = new Zend_Validate_Int();
$validator->setMessage($this->translate('publish_validation_error_int'), Zend_Validate_Int::NOT_INT);
$validators[] = $validator;
return $validators;
}
示例14: formValidator
public function formValidator($form,$formType)
{
$emptyValidator = new Zend_Validate_NotEmpty();
$emptyValidator->setMessage(General_Models_Text::$text_notEmpty);
$form->getElement('sealDate')->setAllowEmpty(false)
->addValidator($emptyValidator);
$form->getElement('returnDate')->setAllowEmpty(false)
->addValidator($emptyValidator);
$form->getElement('name')->setAllowEmpty(false)
->addValidator($emptyValidator);
$form->getElement('sealUser')->setAllowEmpty(false)
->addValidator($emptyValidator);
$form->getElement('contactName')->setAllowEmpty(false)
->addValidator($emptyValidator);
$form->getElement('sealFile')->setAllowEmpty(false)
->addValidator($emptyValidator);
$form->getElement('reason')->setAllowEmpty(false)
->addValidator($emptyValidator);
$form->getElement('copy')->setAllowEmpty(false)
->addValidator($emptyValidator);
$intValidator = new Zend_Validate_Int();
$intValidator->setMessage(General_Models_Text::$text_notInt);
$form->getElement('copy')->addValidator($intValidator);
$dateValidator = new Zend_Validate_Date();
$dateValidator->setMessage(General_Models_Text::$text_notDate);
$form->getElement('sealDate')->addValidator($dateValidator);
$form->getElement('returnDate')->addValidator($dateValidator);
return $form;
}
示例15: init
/**
* @author Ngo Anh Long <ngoanhlong@gmail.com>
* If we use Twitter_Bootstrap3_Form_Horizontal to create a element follow format such as:
* $studentId = $this->createElement('text', 'studentId');
* Then: Type of element you must make it in lower case 'text'
* Because: If you make the type of element in uper case 'Text', bootstrap3 is not active for U
* Beside that: To create a element must follow the format:
* $studentId = $this->createElement('text', 'studentId');
* If you have a recommendation for me, please recomment for me
*/
public function init()
{
// Add some Attributes for this form
// Name of form is: createProfile and method is POST to itsefl
$this->addAttribs(['name' => 'createProfile']);
$this->setMethod("POST");
//Student Id
//Not empty
// Just contains number
// Max length: 25
// Min length: 6
$studentId = $this->createElement('text', 'studentId');
$studentId->setLabel('Mã sinh viên: ');
$studentId->setRequired();
$studentId->addValidator('NotEmpty', true, ['messages' => ['isEmpty' => 'Mã sinh viên yêu cầu không để trống']]);
$studentId->addValidator('digits', true, ['messages' => ['notDigits' => 'Mã sinh viên yêu cầu chỉ được là số']]);
$studentIdLengthValidate = new Zend_Validate_StringLength();
$studentIdLengthValidate->setMax(25);
$studentIdLengthValidate->setMin(6);
$studentIdLengthValidate->setMessage('Mã sinh viên tối thiểu là 6 kí tự', Zend_Validate_StringLength::TOO_SHORT);
$studentIdLengthValidate->setMessage('Mã sinh viên có độ dài tối đa là 25 kí tự', Zend_Validate_StringLength::TOO_LONG);
$studentId->addValidator($studentIdLengthValidate);
// studentName :
// Not empty
// Just contains: Alphabet and allow white space in it
// Max length: 50
// Min length: 6
$studentName = $this->createElement('text', 'studentName');
$studentName->setLabel("Your studentName");
$studentName->setRequired();
$studentName->addValidator('NotEmpty', true, ['messages' => ['isEmpty' => 'Tên sinh viên yêu cầu không để trống']]);
$studentName->addValidator('Alpha', true, ['allowWhiteSpace' => true, 'messages' => ['notAlpha' => 'Tên sinh viên chỉ là chữ']]);
$stringLengthValidate = new Zend_Validate_StringLength();
$stringLengthValidate->setMax(50);
$stringLengthValidate->setMin(6);
$stringLengthValidate->setMessage('Tên sinh viên tối thiểu là 6 kí tự', Zend_Validate_StringLength::TOO_SHORT);
$stringLengthValidate->setMessage('Tên sinh viên có độ dài tối đa là 50 kí tự', Zend_Validate_StringLength::TOO_LONG);
$studentName->addValidator($stringLengthValidate);
// dateOf birth:
// 1. Not Empty
// 2. Must follow this format: dd/mm/YYYY
$dateOfBirth = $this->createElement('text', 'dateOfBirth');
$dateOfBirth->setLabel("Date of birth: ");
$dateOfBirth->setAttrib('placeholder', 'dd/mm/YYYY');
$dateOfBirth->setRequired();
$dateOfBirth->addValidator('NotEmpty', true, ['messages' => ['isEmpty' => 'Ngày sinh yêu cầu không được để trống']]);
$dateValidator = new Zend_Validate_Date();
$dateValidator->setFormat('dd-MM-yyyy');
$dateValidator->setMessage("Ngày sinh của bạn phải theo định dạng: dd/mm/yyyy", Zend_Validate_Date::FALSEFORMAT);
$dateValidator->setMessage("Ngày sinh của bạn phải theo định dạng: dd/mm/yyyy", Zend_Validate_Date::INVALID_DATE);
$dateValidator->setMessage("Ngày sinh của bạn phải theo định dạng: dd/mm/yyyy", Zend_Validate_Date::INVALID);
$dateOfBirth->addValidator($dateValidator);
// Gender is a Select Box
// Default value is 1 - male
// And 0 - Female
// Gender don't need validate because it has default value
$gender = $this->createElement('select', "gender");
$gender->setValue("1");
$gender->setLabel("Gender");
$gender->setMultiOptions(['1' => 'Male', '0' => 'Female']);
// $gender->setRequired();
// $gender->addValidator('NotEmpty', true, [
// 'messages' => [
// 'isEmpty' => 'Giới tính yêu cầu không được để trống'
// ]
// ]);
// Phone number
// Must:
// 1. Not empty
// 2. Is Integer, dont allow white space
// After this validator, when get phone number, add number 0 to head of phone number
// Max length: 12
// Min length: 11
// Note: this rule follows number of Vietnamese phone number
$phone = $this->createElement('text', 'phone');
$phone->setLabel("Your phone: ");
$phone->setRequired();
$phone->addValidator('NotEmpty', true, ['messages' => ['isEmpty' => 'Số điện thoại yêu cầu không để trống']]);
$phoneDigitValidator = new Zend_Validate_Int();
$phoneDigitValidator->setMessage('Số điện thoại chỉ bao gồm các chữ số nguyên', Zend_Validate_Int::NOT_INT);
$phoneLengthValidator = new Zend_Validate_StringLength();
$phoneLengthValidator->setMax(12);
$phoneLengthValidator->setMin(11);
$phoneLengthValidator->setMessage('Số điện thoại tối thiểu 11 chữ số', Zend_Validate_StringLength::TOO_SHORT);
$phoneLengthValidator->setMessage("Số điện thoại chỉ tối đa 12 chữ số", Zend_Validate_StringLength::TOO_LONG);
$phone->addValidator($phoneDigitValidator);
$phone->addValidator($phoneLengthValidator);
// Address
// Contains: 40 columns and 10 rows
// Address can empty is Ok
//.........这里部分代码省略.........