/** * Preapares data for saving of subscriber * Add the line for rapidmail status * * @param Mage_Newsletter_Model_Subscriber $subscriber * @return array */ protected function _prepareSave(Mage_Newsletter_Model_Subscriber $subscriber) { $data = array(); $data['customer_id'] = $subscriber->getCustomerId(); $data['store_id'] = $subscriber->getStoreId() ? $subscriber->getStoreId() : 0; $data['subscriber_status'] = $subscriber->getStatus(); $data['subscriber_email'] = $subscriber->getEmail(); $data['subscriber_confirm_code'] = $subscriber->getCode(); $data['rapidmail_status'] = $subscriber->getRapidmailStatus(); if ($subscriber->getIsStatusChanged()) { $data['change_status_at'] = Mage::getSingleton('core/date')->gmtDate(); } $validators = array('subscriber_email' => 'EmailAddress'); $filters = array(); $input = new Zend_Filter_Input($filters, $validators, $data); $session = Mage::getSingleton($this->_messagesScope); if ($input->hasInvalid() || $input->hasMissing()) { foreach ($input->getMessages() as $message) { if (is_array($message)) { foreach ($message as $error) { $session->addError($error); } } else { $session->addError($message); } } Mage::throwException(Mage::helper('newsletter')->__('Form was filled incorrectly')); } return $data; }
protected function _filterInputIdentify($parameters) { $input = new Zend_Filter_Input(array('*' => 'StripTags', 'username' => 'StringTrim'), array('username' => array(), 'password' => array(), 'uri' => array('allowEmpty' => true)), $parameters, array('presence' => 'required')); if ($input->hasInvalid() or $input->hasMissing()) { throw new Vtx_UserException($this->messageErrorEmpty); } return $input; }
protected function _filterInputServiceArea($params) { $input = new Zend_Filter_Input(array(), array('regional_id' => array('NotEmpty', 'presence' => 'required'), 'StateId' => array('allowEmpty' => true), 'CityId' => array('allowEmpty' => true), 'NeighborhoodId' => array('allowEmpty' => true)), $params); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputEnterpriseProgramaRank($params) { $input = new Zend_Filter_Input(array('*' => array('StripTags', 'StringTrim')), array('enterprise_id_key' => array('allowEmpty' => true), 'user_id' => array('allowEmpty' => true), 'programa_id' => array('allowEmpty' => true), 'classificar' => array('allowEmpty' => true), 'desclassificar' => array('allowEmpty' => true), 'justificativa' => array('allowEmpty' => true), 'classificado_verificacao' => array('allowEmpty' => true), 'desclassificado_verificacao' => array('allowEmpty' => true), 'motivo_desclassificado_verificacao' => array('allowEmpty' => true), 'classificado_ouro' => array('allowEmpty' => true), 'classificado_prata' => array('allowEmpty' => true), 'classificado_bronze' => array('allowEmpty' => true), 'desclassificado_final' => array('allowEmpty' => true), 'motivo_desclassificado_final' => array('allowEmpty' => true), 'classificar_nacional' => array('allowEmpty' => true), 'desclassificar_nacional' => array('allowEmpty' => true), 'motivo_desclassificado_nacional' => array('allowEmpty' => true), 'classificar_fase2_nacional' => array('allowEmpty' => true), 'desclassificar_fase2_nacional' => array('allowEmpty' => true), 'motivo_desclassificado_fase2_nacional' => array('allowEmpty' => true), 'classificado_ouro_nacional' => array('allowEmpty' => true), 'classificado_prata_nacional' => array('allowEmpty' => true), 'classificado_bronze_nacional' => array('allowEmpty' => true), 'classificar_fase3_nacional' => array('allowEmpty' => true), 'desclassificar_fase3_nacional' => array('allowEmpty' => true), 'motivo_desclassificado_fase3_nacional' => array('allowEmpty' => true)), $params); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputAnnualResultData($params) { $input = new Zend_Filter_Input(array('*' => array('StripTags', 'StringTrim'), 'value' => array(array('Alnum', array('allowwhitespace' => true))), 'Year' => array(array('Digits', array('allowwhitespace' => true)))), array('annual_result_id' => array('NotEmpty'), 'year' => array('allowEmpty' => true), 'value' => array('allowEmpty' => true)), $params, array('presence' => 'required')); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputLogCadastroEmpresa($params) { $input = new Zend_Filter_Input(array(), array('user_id_log' => array('NotEmpty', 'presence' => 'required'), 'enterprise_id' => array('NotEmpty', 'messages' => array('Erro ao cadastrar empresa.'), 'presence' => 'required'), 'programa_id' => array('NotEmpty', 'messages' => array('Erro ao cadastrar empresa.'), 'presence' => 'required'), 'acao' => array('NotEmpty', 'messages' => array('Erro ao cadastrar empresa.'), 'presence' => 'required')), $params, array()); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputUserLocality($params) { $input = new Zend_Filter_Input(array(), array('user_id' => array('NotEmpty', 'presence' => 'required'), 'enterprise_id' => array('allowEmpty' => true), 'regional_id' => array('allowEmpty' => true)), $params); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputAnnualResult($params) { $input = new Zend_Filter_Input(array('*' => array('StringTrim'), 'value' => array()), array('question_id' => array(), 'mask' => array('NotEmpty', 'messages' => array('Escolha a máscara do Resultado Anual.')), 'value' => array('NotEmpty', 'messages' => array('Escolha o nome do Resultado Anual.'))), $params, array('presence' => 'required')); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputEmailQueue($params) { $input = new Zend_Filter_Input(array('*' => array('StripTags', 'StringTrim'), 'answer_value' => array(array('Alnum', array('allowwhitespace' => true)))), array('alternative_id' => array('NotEmpty'), 'answer_value' => array('allowEmpty' => true), 'start_time' => array('allowEmpty' => true), 'end_time' => array('allowEmpty' => true), 'answer_date' => array('allowEmpty' => true), 'user_id' => array('NotEmpty'), 'logged_user_id' => array('NotEmpty')), $params, array('presence' => 'required')); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputAddressPresident($params) { $input = new Zend_Filter_Input(array('cep' => array(array('Alnum', array('allowwhitespace' => true)), array('StripTags', 'StringTrim')), 'street_name_full' => array(array('Alnum', array('allowwhitespace' => true)), array('StripTags', 'StringTrim'))), array('address_id' => array('allowEmpty' => true), 'president_id' => array('NotEmpty', 'presence' => 'required'), 'cep' => array('NotEmpty', 'messages' => array('Digite apenas números no CEP da candidata.'), 'presence' => 'required'), 'state_id' => array('NotEmpty', 'messages' => array('Escolha o estado da candidata.')), 'city_id' => array('NotEmpty', 'messages' => array('Escolha a cidade da candidata.')), 'neighborhood_id' => array('NotEmpty', 'messages' => array('Escolha o bairro da candidata.')), 'name_full_log' => array('NotEmpty', 'messages' => array('Digite o nome da Rua da candidata.')), 'street_number' => array('NotEmpty', 'messages' => array('Digite o Número da Rua da candidata.')), 'street_completion' => array('allowEmpty' => true)), $params); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputBlock($params) { $input = new Zend_Filter_Input(array('*' => array('StripTags', 'StringTrim'), 'value' => array(array('Alnum', array('allowwhitespace' => true))), 'long_description' => array(), 'conclusion_text' => array(array('Alnum', array('allowwhitespace' => true)))), array('questionnaire_id' => array('NotEmpty'), 'designation' => array('allowEmpty' => true), 'value' => array('NotEmpty', 'messages' => array('O nome do bloco não pode ser vazio.')), 'long_description' => array('allowEmpty' => true), 'conclusion_text' => array('allowEmpty' => true)), $params, array('presence' => 'required')); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputRoleQuestionnaire($params) { $input = new Zend_Filter_Input(array(), array('role_id' => array('NotEmpty', 'messages' => array('Escolha o Papel (perfil)')), 'questionnaire_id' => array('NotEmpty', 'messages' => array('Escolha o questionário')), 'start_date' => array('NotEmpty', new Zend_Validate_Date('dd/MM/yyyy')), 'end_date' => array('NotEmpty', new Zend_Validate_Date('dd/MM/yyyy'))), $params, array('presence' => 'required')); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputAnswerFeedbackImprove($params) { $input = new Zend_Filter_Input(array('*' => array('StripTags', 'StringTrim')), array('user_id' => array('NotEmpty'), 'answer_id' => array('NotEmpty'), 'feedback_improve' => array('NotEmpty')), $params, array('presence' => 'required')); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputPresident($params) { $input = new Zend_Filter_Input(array('*' => array('StripTags', 'StringTrim'), 'name' => array(), 'cpf' => array('Digits')), array('enterprise_id' => array('NotEmpty', 'presence' => 'required'), 'education_id' => array('NotEmpty', 'messages' => array('Escolha o Nivel de Escolaridade.'), 'presence' => 'required'), 'position_id' => array('NotEmpty', 'messages' => array('Escolha o Cargo.'), 'presence' => 'required'), 'find_us_id' => array('NotEmpty', 'messages' => array('Selecione o item como nos conheceu.'), 'presence' => 'required'), 'name' => array('NotEmpty', 'messages' => array('Digite o Nome da candidata.'), 'presence' => 'required'), 'nick_name' => array('allowEmpty' => true), 'cpf' => array('NotEmpty', 'messages' => array('Digite o CPF.'), new Vtx_Validate_Cpf()), 'email' => array('allowEmpty' => true), 'phone' => array('allowEmpty' => true), 'cellphone' => array('allowEmpty' => true), 'born_date' => array('NotEmpty', 'messages' => array('Digite a Data de Nascimento.'), 'presence' => 'required', new Zend_Validate_Date('dd/MM/yyyy')), 'gender' => array('allowEmpty' => true), 'newsletter_email' => array('allowEmpty' => true), 'newsletter_mail' => array('allowEmpty' => true), 'newsletter_sms' => array('allowEmpty' => true), 'agree' => array('NotEmpty', 'messages' => array('É necessário aceitar o regulamento'), 'presence' => 'required'), 'created' => array('allowEmpty' => true)), $params, array()); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputGroup($params) { $input = new Zend_Filter_Input(array('name' => array(), 'description' => array()), array('name' => array('NotEmpty', 'messages' => array('O Nome não pode ser vazio.')), 'description' => array('NotEmpty', 'messages' => array('A Descrição não pode ser vazia.'))), $params, array('presence' => 'required')); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputQuestion($params) { $input = new Zend_Filter_Input(array('*' => array('StripTags', 'StringTrim'), 'term' => array(array('Alnum', array('allowwhitespace' => true))), 'description' => array(array('HtmlEntities'))), array('term' => array('NotEmpty'), 'description' => array('NotEmpty')), $params, array('presence' => 'required')); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputConfiguration($params) { $input = new Zend_Filter_Input(array('*' => array('StripTags', 'StringTrim')), array(), $params, array('presence' => 'required')); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputECAC($params) { $input = new Zend_Filter_Input(array('*' => array('StripTags', 'StringTrim')), array('enterprise_id' => array('NotEmpty', 'messages' => array('Erro ao cadastrar empresa'), 'presence' => 'required'), 'competition_id' => array('NotEmpty', 'messages' => array('Erro ao cadastrar empresa'), 'presence' => 'required'), 'category_award_id' => array('NotEmpty', 'messages' => array('Escolha a categoria do premio'), 'presence' => 'required'), 'token' => array('allowEmpty' => true)), $params); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
public function filterAnswerForm($parameters) { $filters = array('*' => 'StripTags', 'question_id' => 'StringTrim', 'alternative_id' => 'StringTrim', 'start_time' => 'StringTrim'); $validator = array('question_id' => array('NotEmpty', 'messages' => $this->_messagesError['AnswerFormError'] . 'Questão'), 'alternative_id' => array('NotEmpty', 'messages' => $this->_messagesError['AnswerFormError'] . 'Alternativa'), 'answer_value' => array('allowEmpty' => true), 'start_time' => array('NotEmpty', new Zend_Validate_Date('H:i:s'))); $options = array('presence' => 'required'); $input = new Zend_Filter_Input($filters, $validator, $parameters, $options); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputQuestion($params) { $input = new Zend_Filter_Input(array('*' => array('StripTags', 'StringTrim'), 'question_type_id' => array(array('Alnum', array('allowwhitespace' => true))), 'parent_id' => array(array('Alnum', array('allowwhitespace' => true))), 'designation' => array(array('Alnum', array('allowwhitespace' => true))), 'supporting_text' => array(), 'value' => array(), 'version' => array(), 'status' => array(array('Alnum', array('allowwhitespace' => true)))), array('question_type_id' => array('NotEmpty'), 'parent_id' => array('NotEmpty'), 'designation' => array('NotEmpty'), 'supporting_text' => array('allowEmpty' => true), 'value' => array('NotEmpty', 'messages' => array('O nome da questão não pode ser vazia.')), 'version' => array(), 'status' => array('NotEmpty')), $params, array('presence' => 'required')); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputRole($params) { $input = new Zend_Filter_Input(array('*' => array('StripTags', 'StringTrim'), 'roleName' => array('Alpha', array('StringToLower', 'encoding' => 'UTF-8'), new Vtx_Filter_Transliterate())), array('longDescription' => array('NotEmpty'), 'roleName' => array('NotEmpty', 'messages' => $this->_messagesError['roleNameExists'])), $params, array('presence' => 'required')); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputEnterprise($params) { $input = new Zend_Filter_Input(array('*' => array('StripTags', 'StringTrim'), 'cnpj' => array(array('Digits')), 'employees_quantity' => array(array('Digits'))), array('social_name' => array('NotEmpty', 'messages' => array('Digite a Razão Social'), 'presence' => 'required'), 'fantasy_name' => array('NotEmpty', 'messages' => array('Digite o Nome Fantasia'), 'presence' => 'required'), 'status' => array('allowEmpty' => true), 'cnpj' => array('allowEmpty' => true, new Vtx_Validate_Cnpj()), 'creation_date' => array('NotEmpty', new Zend_Validate_Date('dd/MM/yyyy')), 'employees_quantity' => array('NotEmpty', 'messages' => array('Número de colaboradores: Digite apenas números.'), 'Digits'), 'annual_revenue' => array('NotEmpty', 'messages' => array('Escolha o Porte da Empresa.'), 'presence' => 'required'), 'cnae' => array('allowEmpty' => true), 'email_default' => array('allowEmpty' => true), 'phone' => array('NotEmpty', 'messages' => array('Digite o telefone.'), 'presence' => 'required'), 'site' => array('allowEmpty' => true), 'company_history' => array('NotEmpty', 'messages' => array('Digite o Resumo da empresa.'), 'presence' => 'required'), 'category_sector_id' => array('NotEmpty', 'messages' => array('Escolha a Categoria setorial.'), 'presence' => 'required'), 'category_award_id' => array('NotEmpty', 'messages' => array('Escolha a Categoria do Premio.'), 'presence' => 'required'), 'state_registration' => array('allowEmpty' => true), 'dap' => array('allowEmpty' => true), 'register_ministry_fisher' => array('allowEmpty' => true), 'nirf' => array('allowEmpty' => true), 'farm_size' => array('allowEmpty' => true), 'register_ministry_fisher' => array('allowEmpty' => true), 'hasnt_email' => array('allowEmpty' => true)), $params); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
/** * @group ZF-3736 */ public function testTranslateNotEmptyMessagesByUsingRegistry() { require_once 'Zend/Translate/Adapter/Array.php'; $translator = new Zend_Translate_Adapter_Array(array('missingMessage' => 'Still missing'), 'en'); require_once 'Zend/Registry.php'; Zend_Registry::set('Zend_Translate', $translator); $validators = array('rule1' => array('presence' => 'required', 'fields' => array('field1', 'field2'), 'default' => array('field1default'))); $data = array(); $input = new Zend_Filter_Input(null, $validators, $data); $this->assertTrue($input->hasMissing(), 'Expected hasMissing() to return true'); $this->assertFalse($input->hasInvalid(), 'Expected hasInvalid() to return false'); $this->assertFalse($input->hasUnknown(), 'Expected hasUnknown() to return false'); $this->assertFalse($input->hasValid(), 'Expected hasValid() to return false'); $missing = $input->getMissing(); $this->assertType('array', $missing); $this->assertEquals(array('rule1'), array_keys($missing)); $this->assertEquals(array("Still missing"), $missing['rule1']); }
protected function _filterInputUser($params) { $input = new Zend_Filter_Input(array('*' => array('StripTags', 'StringTrim')), array('first_name' => array('NotEmpty', 'messages' => array('Digite o Nome da candidata.'), 'presence' => 'required'), 'surname' => array('allowEmpty' => true), 'email' => array('allowEmpty' => true), 'login' => array('allowEmpty' => true), 'password' => array(), 'position_id' => array('allowEmpty' => true), 'education_id' => array('allowEmpty' => true), 'born_date' => array('allowEmpty' => true), 'gender' => array('allowEmpty' => true), 'cpf' => array('allowEmpty' => true, new Vtx_Validate_Cpf()), 'password_hint' => array('allowEmpty' => true), 'status' => array('allowEmpty' => true)), $params); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputAppraiserToEnterprise($params) { $input = new Zend_Filter_Input(array('enterprise_id' => array()), array('enterprise_id' => array('NotEmpty', 'messages' => array('Empresa não informada.'))), $params, array('presence' => 'required')); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
protected function _filterInputReport($params) { $input = new Zend_Filter_Input(array('*' => array('StripTags', 'StringTrim'), 'report' => array(), 'title' => array()), array('enterprise_id' => array('allowEmpty' => true), 'competition_id' => array('allowEmpty' => true), 'report' => array('allowEmpty' => true), 'title' => array('allowEmpty' => true)), $params); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
public function testProcessMissingThrowsException() { $data = array('field1' => 'ab&c'); $filters = array('*' => 'StringTrim', 'field2' => 'digits'); $validators = array('field1' => array(Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'field2' => array('digits', Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_REQUIRED)); $input = new Zend_Filter_Input($filters, $validators, $data); try { $input->process(); $this->fail('Expected to catch Zend_Filter_Exception'); } catch (Zend_Exception $e) { $this->assertType('Zend_Filter_Exception', $e, 'Expected object of type Zend_Filter_Exception, got ' . get_class($e)); $this->assertEquals("Input has missing fields", $e->getMessage()); $this->assertTrue($input->hasMissing(), 'Expected hasMissing() to return true'); $this->assertFalse($input->hasInvalid(), 'Expected hasInvalid() to return false'); $this->assertFalse($input->hasUnknown(), 'Expected hasUnknown() to return false'); $this->assertTrue($input->hasValid(), 'Expected hasValid() to return true'); } }
protected function _filterInputQuestionTip($params) { $input = new Zend_Filter_Input(array('*' => array('StripTags', 'StringTrim'), 'question_id' => array(array('Alnum', array('allowwhitespace' => false))), 'question_tip_type_id' => array(array('Alnum', array('allowwhitespace' => false))), 'value' => array()), array('question_id' => array('NotEmpty'), 'question_tip_type_id' => array('NotEmpty'), 'value' => array('NotEmpty')), $params, array('presence' => 'required')); if ($input->hasInvalid() || $input->hasMissing()) { throw new Vtx_UserException(Model_ErrorMessage::getFirstMessage($input->getMessages())); } return $input; }
public function viewAction() { $id = $this->_request->getParam('id'); $captchaCode = $this->_request->getParam('captcha_code'); $modelBlog = new Page(); $blog = $modelBlog->getPage($id); if ($blog) { $this->view->blog = $blog; // tags $modelTags = new Tags(); $where = array('blog_id' => $id); $tags = $modelTags->getTags($where); if ($tags) { $this->view->tags = $tags; } // 评论 $modelComment = new Comment(); $comments = $modelComment->getComments($id); $this->view->comments = $comments; $dataComment = $this->_request->getPost(); // 获取表单提交值 if ($dataComment) { if ($dataComment['captcha'] == $captchaCode) { // 定义过滤规则 $filters = array('name' => array('StringTrim'), 'comment' => 'StripTags'); // 定义验证规则 $validators = array('name' => array(array('StringLength', 3, 16), 'NotEmpty', Zend_Filter_Input::MESSAGES => array(array(Zend_Validate_StringLength::INVALID => "请输入一个合法的字符串", Zend_Validate_StringLength::TOO_SHORT => "请输入字符长度为3-16", Zend_Validate_StringLength::TOO_LONG => "请输入字符长度为3-16"))), 'email' => array('EmailAddress', Zend_Filter_Input::MESSAGES => array(array(Zend_Validate_EmailAddress::INVALID_FORMAT => "邮件格式不正确,请重新输入。"))), 'comment' => array()); // 实例化过滤器并进行过滤验证 $data = $_POST; $filterPost = new Zend_Filter_Input($filters, $validators, $data); if ($filterPost->hasInvalid() || $filterPost->hasMissing()) { $messages = $filterPost->getMessages(); foreach ($messages as $message) { foreach ($message as $value) { echo $value . "<br />"; } } } // 将经过验证的数据写入数据库 $modelComment = new Comment(); $newComment = $modelComment->createComment($pid = $id, $filterPost->name, $filterPost->email, $filterPost->comment); if ($newComment) { $this->_redirect('/blog/view/id/' . $id); } else { echo "评论提交出错!"; } } else { echo "验证码错误,请刷新后重新输入。"; } } // 生成验证码 $this->captcha_session = new Zend_Session_Namespace('captcha'); //在默认构造函数里实例化 $captcha = new Zend_Captcha_Image(array('font' => 'images/SIMYOU.TTF', 'session' => $this->captcha_session, 'fontsize' => 15, 'imgdir' => 'images/code/', 'width' => 120, 'height' => 30, 'gcFreq' => 3, 'dotNoiseLevel' => 5, 'lineNoiseLevel' => 1, 'wordlen' => 4)); $captcha->generate(); // 生成图片 // 界面方式 $this->view->img_dir = $captcha->getImgDir(); $this->view->captcha_id = $captcha->getId(); //图片文件名,md5编码 $this->view->captcha_code = $captcha->getWord(); $this->view->id = $id; } else { echo "该博客文章不存在!"; } }
/** * Creates a Conjoon_Error_Form based on the fields that where marked as * errorneous in the passed filter-instance. * * @param Zend_Filter_Input $filter * @param Zend_Filter_Exception $e * * @return Conjoon_Error_Form */ public static function fromFilter(Zend_Filter_Input $filter, Zend_Filter_Exception $e) { $error = self::fromException($e, 'Conjoon_Error_Form'); $fields = array(); if ($filter->hasMissing()) { foreach ($filter->getMissing() as $f => $mes) { $fields[$f] = array_values($mes); } } else { if ($filter->hasInvalid()) { foreach ($filter->getInvalid() as $f => $mes) { $fields[$f] = array_values($mes); } } } $error->setMessage("Error in user input. The following fields " . "where missing or contained invalid data: " . implode('; ', array_keys($fields))); $error->setLevel(self::LEVEL_WARNING); $error->setFields($fields); return $error; }