/** * Performs the server-side validation * * Before the Rules added to the element kick in, the element checks the * error code added to the $_FILES array by PHP. If the code isn't * UPLOAD_ERR_OK or UPLOAD_ERR_NO_FILE then a built-in error message will be * displayed and no further validation will take place. * * @return boolean Whether the element is valid */ protected function validate() { if (strlen($this->error)) { return false; } if (isset($this->value['error']) && !in_array($this->value['error'], array(UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE))) { $errorMessage = $this->messageProvider instanceof HTML_QuickForm2_MessageProvider ? $this->messageProvider->get(array('file', $this->value['error']), $this->language) : call_user_func($this->messageProvider, array('file', $this->value['error']), $this->language); if (UPLOAD_ERR_INI_SIZE == $this->value['error']) { $iniSize = ini_get('upload_max_filesize'); $size = intval($iniSize); switch (strtoupper(substr($iniSize, -1))) { case 'G': $size *= 1024; case 'M': $size *= 1024; case 'K': $size *= 1024; } } elseif (UPLOAD_ERR_FORM_SIZE == $this->value['error']) { foreach ($this->getDataSources() as $ds) { if ($ds instanceof HTML_QuickForm2_DataSource_Submit) { $size = intval($ds->getValue('MAX_FILE_SIZE')); break; } } } $this->error = isset($size) ? sprintf($errorMessage, $size) : $errorMessage; return false; } return parent::validate(); }
/** * Performs the server-side validation. * Checks captcha validation first, continues with * defined rules if captcha is valid * * @return boolean Whether the element is valid */ protected function validate() { // Alternative: use custom rule to get error messages if (!$this->verifyCaptcha()) { $this->setError($this->data['captchaSolutionWrong']); return false; } return parent::validate(); }