/**
  * Validate the form
  *
  * @return  void
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         if ($this->frm->getField('filename')->isFilled()) {
             // correct extension?
             if ($this->frm->getField('filename')->isAllowedExtension(array('jpg', 'jpeg', 'gif', 'png'), BL::err('JPGGIFAndPNGOnly'))) {
                 // correct mimetype?
                 $this->frm->getField('filename')->isAllowedMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'), BL::err('JPGGIFAndPNGOnly'));
             }
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['language'] = $this->record['language'];
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['caption'] = $this->frm->getField('caption')->getValue(true);
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             // get module settings
             $dimensions = $this->get('fork.settings')->getForModule('Slideshow');
             // the extra data
             $data = array('link' => null);
             // links
             if ($this->frm->getField('internal_url')->isFilled()) {
                 $data['link'] = array('type' => 'internal', 'id' => $this->frm->getField('internal_url')->getValue());
             }
             // external links
             if ($this->frm->getField('external_link')->getChecked()) {
                 $data['link'] = array('type' => 'external', 'url' => $this->frm->getField('external_url')->getValue());
             }
             $item['data'] = serialize($data);
             if ($this->frm->getField('filename')->isFilled()) {
                 // only delete the picture when there is one allready
                 if (!empty($this->record['filename'])) {
                     $fs = new Filesystem();
                     $fs->remove(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $this->record['filename']);
                     $fs->remove(FRONTEND_FILES_PATH . '/slideshow/' . $this->record['filename']);
                 }
                 // create new filename
                 $filename = time() . "." . $this->frm->getField('filename')->getExtension();
                 // add filename to item
                 $item['filename'] = $filename;
                 // If height is not set, scale the image proportionally to the given width
                 if ($this->gallery['height'] != 0) {
                     // upload image width gallery dimensions
                     $this->frm->getField('filename')->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/' . $filename, $this->gallery['width'], $this->gallery['height'], true, false, 100);
                 } else {
                     $this->frm->getField('filename')->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/' . $filename, $this->gallery['width'], null, true, true, 100);
                 }
                 // create thumbnail
                 $this->frm->getField('filename')->createThumbnail(FRONTEND_FILES_PATH . '/slideshow/thumbnails/' . $filename, 100, 100, false, false, 100);
             }
             // update image values in database
             BackendSlideshowModel::updateImage($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Edit') . '&report=Saved&id=' . $this->galleryId . '&highlight=' . $this->id . '#images');
         }
     }
 }