/** * This function will return the errors. It is extended so we can do file checks automatically. * * @return string */ public function getErrors() { // if the image is bigger then the allowed configuration it won't show up as filled but it is submitted // the empty check is added because otherwise this error is shown like 7 times if ($this->isSubmitted() && isset($_FILES[$this->getName()]['error']) && empty($this->errors)) { $imageError = $_FILES[$this->getName()]['error']; if ($imageError === UPLOAD_ERR_INI_SIZE && empty($this->errors)) { $this->addError(SpoonFilter::ucfirst(sprintf(BackendLanguage::err('FileTooBig'), Form::getUploadMaxFileSize()))); } } return $this->errors; }
/** * Parses the html for this filefield. * * @param TwigTemplate $template The template to parse the element in. * * @throws \SpoonFormException * * @return string */ public function parse($template = null) { // name is required if ($this->attributes['name'] == '') { throw new \SpoonFormException('A name is required for a file field. Please provide a name.'); } // start html generation $output = '<input type="file"'; // add attributes $output .= $this->getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'])) . ' />'; // add help txt if needed if (!$this->hideHelpTxt) { $output .= '<p class="help-block">' . sprintf(BackendLanguage::getMessage('HelpImageFieldWithMaxFileSize', 'core'), Form::getUploadMaxFileSize()) . '</p>'; } // parse to template if ($template !== null) { $template->assign('file' . SpoonFilter::toCamelCase($this->attributes['name']), $output); $template->assign('file' . SpoonFilter::toCamelCase($this->attributes['name']) . 'Error', $this->errors != '' ? '<span class="formError text-danger">' . $this->errors . '</span>' : ''); } return $output; }