/** * 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(); // shorten values $pagePath = $this->frm->getField('page_path')->getValue(); if (count($this->linkList) > 1) { $pageList = $this->frm->getField('page_list')->getSelected(); } // get the target if ($this->frm->getfield('page_path')->isFilled()) { $page = $pagePath; } elseif ($pageList == '0') { $page = null; } else { $page = SITE_MULTILANGUAGE ? substr($pageList, strpos($pageList, '/', 1)) : $pageList; } // validate fields if (isset($page) && !SpoonFilter::isURL(SITE_URL . $page)) { $this->frm->getField('page_path')->addError(BL::err('InvalidURL')); } if (!isset($page)) { $this->frm->getField('page_path')->addError(BL::err('FieldIsRequired')); } if (!$this->frm->getField('page_path')->isFilled() && !$this->frm->getfield('page_list')->isFilled()) { $this->frm->getField('page_path')->addError(BL::err('FieldIsRequired')); } // no errors? if ($this->frm->isCorrect()) { // get metrics $metrics = BackendAnalyticsHelper::getMetricsForPage($page, $this->startTimestamp, $this->endTimestamp); // build item $item['page_path'] = $page; $item['entrances'] = isset($metrics['entrances']) ? $metrics['entrances'] : 0; $item['bounces'] = isset($metrics['bounces']) ? $metrics['bounces'] : 0; $item['bounce_rate'] = ($metrics['entrances'] == 0 ? 0 : number_format((int) $metrics['bounces'] / $metrics['entrances'] * 100, 2)) . '%'; $item['start_date'] = date('Y-m-d', $this->startTimestamp) . ' 00:00:00'; $item['end_date'] = date('Y-m-d', $this->endTimestamp) . ' 00:00:00'; $item['updated_on'] = date('Y-m-d H:i:s'); // insert the item $item['id'] = (int) BackendAnalyticsModel::insertLandingPage($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_landing_page', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('landing_pages') . '&report=saved&var=' . urlencode($item['page_path'])); } } }