Автор: Jan Schneider (jan@horde.org)
Наследование: extends Horde_Translation_Autodetect
Пример #1
0
 function isValid(&$var, &$vars, $value, &$message)
 {
     if (empty($value) && $var->isRequired()) {
         $message = Horde_Form_Translation::t("This field is required.");
         return false;
     }
     return true;
 }
Пример #2
0
 /**
  * Validates this variable.
  *
  * @param Variables $vars  The {@link Variables} instance of the submitted
  *                         form.
  * @param string $message  A variable passed by reference that will be
  *                         assigned a descriptive error message if
  *                         validation failed.
  *
  * @return boolean  True if the variable validated.
  */
 function validate(&$vars, &$message)
 {
     if ($this->_arrayVal) {
         $vals = $this->getValue($vars);
         if (!is_array($vals)) {
             if ($this->required) {
                 $message = Horde_Form_Translation::t("This field is required.");
                 return false;
             } else {
                 return true;
             }
         }
         foreach ($vals as $i => $value) {
             if ($value === null && $this->required) {
                 $message = Horde_Form_Translation::t("This field is required.");
                 return false;
             } else {
                 if (!$this->type->isValid($this, $vars, $value, $message)) {
                     return false;
                 }
             }
         }
     } else {
         $value = $this->getValue($vars);
         return $this->type->isValid($this, $vars, $value, $message);
     }
     return true;
 }
Пример #3
0
 /**
  * Validates the form, checking if it really has been submitted by calling
  * isSubmitted() and if true does any onSubmit() calls for variable types
  * in the form. The _submitted variable is then rechecked.
  *
  * @param Variables $vars       A Variables instance, optional since Horde
  *                              3.2.
  * @param boolean $canAutofill  Can the form be valid without being
  *                              submitted?
  *
  * @return boolean  True if the form is valid.
  */
 function validate($vars = null, $canAutoFill = false)
 {
     if (is_null($vars)) {
         $vars = $this->_vars;
     }
     /* Get submitted status. */
     if ($this->isSubmitted() || $canAutoFill) {
         /* Form was submitted or can autofill; check for any variable
          * types' onSubmit(). */
         $this->onSubmit($vars);
         /* Recheck submitted status. */
         if (!$this->isSubmitted() && !$canAutoFill) {
             return false;
         }
     } else {
         /* Form has not been submitted; return false. */
         return false;
     }
     $message = '';
     $this->_autofilled = true;
     if ($this->_useFormToken) {
         $tokenSource = $GLOBALS['injector']->getInstance('Horde_Token');
         $passedToken = $vars->get($this->_name . '_formToken');
         if (!empty($passedToken) && !$tokenSource->verify($passedToken)) {
             $this->_errors['_formToken'] = Horde_Form_Translation::t("This form has already been processed.");
         }
         if (!$GLOBALS['session']->get('horde', 'form_secrets/' . $passedToken)) {
             $this->_errors['_formSecret'] = Horde_Form_Translation::t("Required secret is invalid - potentially malicious request.");
         }
     }
     foreach ($this->getVariables() as $var) {
         $this->_autofilled = $var->_autofilled && $this->_autofilled;
         if (!$var->validate($vars, $message)) {
             $this->_errors[$var->getVarName()] = $message;
         }
     }
     if ($this->_autofilled) {
         unset($this->_errors['_formToken']);
     }
     foreach ($this->_hiddenVariables as $var) {
         if (!$var->validate($vars, $message)) {
             $this->_errors[$var->getVarName()] = $message;
         }
     }
     return $this->isValid();
 }
Пример #4
0
 /**
  * Implementation specific begin function.
  */
 function _renderBeginActive($name, $extra)
 {
     echo '<div class="horde-form" id="' . htmlspecialchars($this->_name) . '_active">';
     if ($this->_showHeader) {
         $this->_sectionHeader($name, $extra);
     }
     if ($this->_requiredLegend) {
         echo '<span class="horde-form-error">' . $this->_requiredMarker . '</span> = ' . Horde_Form_Translation::t("Required Field");
     }
 }
Пример #5
0
 /**
  * Returns the plural translation of a message.
  *
  * @param string $singular  The singular version to translate.
  * @param string $plural    The plural version to translate.
  * @param integer $number   The number that determines singular vs. plural.
  *
  * @return string  The string translation, or the original string if no
  *                 translation exists.
  */
 public static function ngettext($singular, $plural, $number)
 {
     self::$_domain = 'Horde_Form';
     self::$_directory = '@data_dir@' == '@' . 'data_dir' . '@' ? __DIR__ . '/../../../locale' : '@data_dir@/Horde_Form/locale';
     return parent::ngettext($singular, $plural, $number);
 }
Пример #6
0
 /**
  * Return info about field type.
  */
 function about()
 {
     return array('name' => Horde_Form_Translation::t("Table Set"), 'params' => array('values' => array('label' => Horde_Form_Translation::t("Values"), 'type' => 'stringlist'), 'header' => array('label' => Horde_Form_Translation::t("Headers"), 'type' => 'stringlist')));
 }