/** * Validate minimum length and min required * word count of body * * @throws \Lampcms\HttpResponseCodeException * * @return object $this */ protected function validateBody() { $minChars = $this->Registry->Ini->MIN_ANSWER_CHARS; $minWords = $this->Registry->Ini->MIN_ANSWER_WORDS; $body = $this->Submitted->getBody(); $oHtmlString = HTMLString::stringFactory($body); $wordCount = $oHtmlString->getWordsCount(); $len = $oHtmlString->length(); if ($len < $minChars) { throw new \Lampcms\HttpResponseCodeException('Answer must contain at least ' . $minChars . ' letters', 400); } if ($wordCount < $minWords) { throw new \Lampcms\HttpResponseCodeException('Answer must contain at least ' . $minWords . ' words', 400); } return $this; }
/** * Enforce config values MIN_ANSWER_CHARS * and MIN_ANSWER_WORDS * * @todo Translate strings of error messages * * (non-PHPdoc) * @see Lampcms\Forms.Form::doValidate() * * @return \Lampcms\Forms\object $this|void */ protected function doValidate() { $minChars = $this->Registry->Ini->MIN_ANSWER_CHARS; $minWords = $this->Registry->Ini->MIN_ANSWER_WORDS; $body = $this->Registry->Request->getUTF8('qbody'); $oHtmlString = HTMLString::stringFactory($body); $wordCount = $oHtmlString->getWordsCount(); $len = $oHtmlString->length(); if ($len < $minChars) { $this->setError('qbody', 'Answer must contain at least ' . $minChars . ' letters'); } if ($wordCount < $minWords) { $this->setError('qbody', 'Answer must contain at least ' . $minWords . ' words'); } return $this; }
/** * Validate min number of words in question * and min number of chars in question * * @return object $this */ protected function validateBody() { $minChars = $this->Registry->Ini->MIN_QUESTION_CHARS; $minWords = $this->Registry->Ini->MIN_QUESTION_WORDS; $body = $this->Registry->Request->getUTF8('qbody'); $oHtmlString = HTMLString::factory($body); $wordCount = $oHtmlString->getWordsCount(); $len = $oHtmlString->length(); if ($len < $minChars) { /** * @todo Translate string */ $this->setError('qbody', 'Question must contain at least ' . $minChars . ' letters'); } if ($wordCount < $minWords) { /** * @todo Translate string */ $this->setError('qbody', 'Question must contain at least ' . $minWords . ' words'); } return $this; }