/** * Check for a valid option (see #4383) */ public function validate() { $varValue = $this->getPost($this->strName); if (!empty($varValue) && !$this->isValidOption($varValue)) { $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['invalid'], is_array($varValue) ? implode(', ', $varValue) : $varValue)); } parent::validate(); }
/** * Validate the widget using the value. * * @param Widget $widget The widget to validate. * * @param string|null $value The value to validate. * * @return void * * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ protected function validateWidget($widget, $value) { if (null === $value) { return; } $name = $widget->name; // Backup $_POST value. $keeper = Input::post($name); Input::setPost($name, $value); $widget->validate(); // Restore $_POST value. Input::setPost($name, $keeper); }
/** * Validate the subscription form * * @param Widget $objWidget * * @return array|bool */ protected function validateForm(Widget $objWidget = null) { // Validate the e-mail address $varInput = \Idna::encodeEmail(\Input::post('email', true)); if (!\Validator::isEmail($varInput)) { $this->Template->mclass = 'error'; $this->Template->message = $GLOBALS['TL_LANG']['ERR']['email']; return false; } $this->Template->email = $varInput; // Validate the channel selection $arrChannels = \Input::post('channels'); if (!is_array($arrChannels)) { $this->Template->mclass = 'error'; $this->Template->message = $GLOBALS['TL_LANG']['ERR']['noChannels']; return false; } $arrChannels = array_intersect($arrChannels, $this->nl_channels); // see #3240 if (!is_array($arrChannels) || empty($arrChannels)) { $this->Template->mclass = 'error'; $this->Template->message = $GLOBALS['TL_LANG']['ERR']['noChannels']; return false; } $this->Template->selectedChannels = $arrChannels; // Check if there are any new subscriptions $arrSubscriptions = array(); if (($objSubscription = \NewsletterRecipientsModel::findBy(array("email=? AND active=1"), $varInput)) !== null) { $arrSubscriptions = $objSubscription->fetchEach('pid'); } $arrRemove = array_intersect($arrChannels, $arrSubscriptions); if (!is_array($arrRemove) || empty($arrRemove)) { $this->Template->mclass = 'error'; $this->Template->message = $GLOBALS['TL_LANG']['ERR']['unsubscribed']; return false; } // Validate the captcha if ($objWidget !== null) { $objWidget->validate(); if ($objWidget->hasErrors()) { return false; } } return array($varInput, $arrRemove); }