Пример #1
0
 /**
  * Check whether $value is a valid CSRF token
  *
  * @param   string      $value          The value to check
  * @param   mixed       $context        Context to use
  *
  * @return  bool                        True, in case the CSRF token is valid
  *
  * @throws  InvalidCSRFTokenException   In case the CSRF token is not valid
  */
 public function isValid($value, $context = null)
 {
     if (parent::isValid($value, $context) && $this->isValidCsrfToken($value)) {
         return true;
     }
     throw new InvalidCSRFTokenException();
 }
Пример #2
0
 /**
  * Constructor
  *
  * @param   string|array|Zend_Config    $spec       Element name or configuration
  * @param   string|array|Zend_Config    $options    Element value or configuration
  */
 public function __construct($spec, $options = null)
 {
     if (is_string($spec) && (null !== $options && is_string($options))) {
         $options = array('label' => $options);
     }
     if (!isset($options['ignore'])) {
         $options['ignore'] = true;
     }
     parent::__construct($spec, $options);
     if ($label = $this->getLabel()) {
         // Necessary to get the label shown on the generated HTML
         $this->content = $label;
     }
 }
Пример #3
0
 /**
  * (non-PHPDoc)
  * @see \Zend_Form_Element::isValid() For the method documentation.
  */
 public function isValid($value, $context = null)
 {
     $this->setValue($value);
     $value = $this->getValue();
     if (!is_numeric($value)) {
         $this->addError(sprintf($this->translate('\'%s\' is not a valid number'), $value));
         return false;
     }
     return parent::isValid($value, $context);
 }
Пример #4
0
 /**
  * Is the date and time valid?
  *
  * @param   string|DateTime     $value
  * @param   mixed               $context
  *
  * @return  bool
  */
 public function isValid($value, $context = null)
 {
     if (!parent::isValid($value, $context)) {
         return false;
     }
     if (!$value instanceof DateTime) {
         $format = $this->getFormat();
         $dateTime = DateTime::createFromFormat($format, $value);
         if ($dateTime === false) {
             $dateTime = DateTime::createFromFormat(substr($format, 0, strrpos($format, ':')), $value);
         }
         $this->setValue($dateTime);
     }
     return true;
 }