public function positiveFloatRegExpHook($strRegexp, $varValue, \Widget $objWidget)
 {
     if ($strRegexp == 'posfloat') {
         if (strpos($varValue, ',') != false) {
             $objWidget->addError($GLOBALS['TL_LANG']['ERR']['posFloat']['commaFound']);
         }
         if (!preg_match('/^\\d+(?:\\.\\d+)?$/', $varValue)) {
             $objWidget->addError($GLOBALS['TL_LANG']['ERR']['posFloat']['noFloat']);
         }
         return true;
     }
     return false;
 }
 /**
  * Add the custom regexp "dezimal" to Contao.
  */
 public function hookAddCustomRegexp($strRegexp, $varValue, \Widget $objWidget)
 {
     if ($strRegexp == 'dezimal') {
         if (!preg_match('/^\\-?\\d+(,\\d+)?$/', trim($varValue))) {
             $objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['digit'], $objWidget->label));
         }
         return true;
     }
     return false;
 }
 public function validateVotingEmailFormField(\Widget $objWidget, $intId)
 {
     if (($objForm = \FormModel::findBy('alias', str_replace('auto_', '', $intId))) !== null && $objForm->maxVoteCount) {
         // check if a voting from the mail address already exists
         $db = \Database::getInstance();
         $objEmailCheck = $db->prepare('SELECT * FROM tl_formdata_details fdt INNER JOIN tl_formdata fd ON fdt.pid=fd.id INNER JOIN tl_form f ON fd.form=f.title WHERE fdt.ff_name=? AND fdt.value=? AND f.alias=?')->execute('email', $objWidget->value, $objForm->alias);
         if ($objEmailCheck->numRows > 0 && $objEmailCheck->numRows >= $objForm->maxVoteCount) {
             $objWidget->addError(sprintf($GLOBALS['TL_LANG']['email_voting']['maxVoteCount'], $objForm->maxVoteCount));
         }
     }
     return $objWidget;
 }
Exemple #4
0
 /**
  * Validate a custom regular expression
  * @param string
  * @param mixed
  * @param object
  * @return boolean
  */
 public function validateRegexp($strRegexp, $varValue, Widget $objWidget)
 {
     switch ($strRegexp) {
         case 'price':
             if (!preg_match('/^[\\d \\.-]*$/', $varValue)) {
                 $objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['digit'], $objWidget->label));
             }
             return true;
             break;
         case 'discount':
             if (!preg_match('/^[-+]\\d+(\\.\\d{1,2})?%?$/', $varValue)) {
                 $objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['discount'], $objWidget->label));
             }
             return true;
             break;
         case 'surcharge':
             if (!preg_match('/^-?\\d+(\\.\\d{1,2})?%?$/', $varValue)) {
                 $objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['surcharge'], $objWidget->label));
             }
             return true;
             break;
     }
     return false;
 }
 protected static function doCheckForDoubleReviews(\Widget $objWidget, $varValue, $strTable)
 {
     if ($strTable == 'tl_competition_review' && ($objReview = ReviewModel::findByPk(\Input::get('id'))) !== null) {
         $objReviews = \HeimrichHannot\Competition\ReviewModel::findOneBy(array('sid=?', 'jid=?', 'tl_competition_review.id!=?'), array($varValue, $objReview->jid, \Input::get('id')));
         // check for already existing reviews by the member for the current submission
         if ($objReviews !== null) {
             $objWidget->addError($GLOBALS['TL_LANG']['MSC']['reviewAlreadyExisting']);
         }
     }
 }
Exemple #6
0
 /**
  * Handle the onsave_callback for a widget.
  *
  * @param array   $field  The field DCA.
  *
  * @param \Widget $widget The widget to validate.
  *
  * @param mixed   $value  The value.
  *
  * @return mixed
  */
 protected function handleSaveCallback($field, $widget, $value)
 {
     $newValue = $value;
     if (is_array($field['save_callback'])) {
         foreach ($field['save_callback'] as $callback) {
             $this->import($callback[0]);
             try {
                 $newValue = $this->{$callback}[0]->{$callback}[1]($newValue, $this);
             } catch (\Exception $e) {
                 $widget->addError($e->getMessage());
                 $this->blnSubmitInput = false;
                 return $value;
             }
         }
     }
     return $newValue;
 }
Exemple #7
0
 /**
  * Check for customer regular expression
  *
  * @param string $strRegexp
  *
  * @param string $varValue
  *
  * @param Widget $objWidget
  *
  * @return boolean
  */
 public function customRegexp($strRegexp, $varValue, Widget $objWidget)
 {
     switch ($strRegexp) {
         case 'colorRgb':
             if (!preg_match('/^([0-9a-f]{3}|[0-9a-f]{6})$/i', $varValue)) {
                 $objWidget->addError('Field ' . $objWidget->label . ' should be a color RGB code.');
             }
             return true;
             break;
     }
     return false;
 }