/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validate fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); if ($this->frm->getField('image')->isFilled()) { $this->frm->getField('image')->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly')); $this->frm->getField('image')->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly')); } $this->meta->validate(); if ($this->frm->isCorrect()) { // build item $item['title'] = $this->frm->getField('title')->getValue(); $item['meta_id'] = $this->meta->save(); $item['sequence'] = BackendCatalogModel::getMaximumCategorySequence() + 1; $item['language'] = Language::getWorkingLanguage(); // the image path $imagePath = FRONTEND_FILES_PATH . '/catalog/brands'; // create folders if needed $fs = new Filesystem(); if (!$fs->exists($imagePath . '/source')) { $fs->mkdir($imagePath . '/source'); } if (!$fs->exists($imagePath . '/150x150')) { $fs->mkdir($imagePath . '/150x150'); } // is there an image provided? if ($this->frm->getField('image')->isFilled()) { // build the image name $item['image'] = $this->meta->getUrl() . '.' . $this->frm->getField('image')->getExtension(); // upload the image & generate thumbnails $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']); } // save the data $item['id'] = BackendCatalogModel::insertBrand($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_brand', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('brands') . '&report=added-brand&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']); } } }