Ejemplo n.º 1
0
 /**
  * Constructor
  *
  * @param array $options
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     if (!empty($options['html'])) {
         $this->setHtml($options['html']);
     }
 }
Ejemplo n.º 2
0
 /**
  * Constructor
  *
  * @param array $options
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     $this->removeAttribute('id');
     // This field has two inputs. We need to implement support of two different ID's or remove such feature :)
     $this->addValidator('Antispam');
 }
Ejemplo n.º 3
0
 public function __construct($options = array())
 {
     if (!empty($options['optionName'])) {
         $this->optionName = $options['optionName'];
     }
     parent::__construct($options);
 }
Ejemplo n.º 4
0
 /**
  * Constructor
  *
  * @param array $options
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     if (!empty($options['mode'])) {
         $this->setMode($options['mode']);
     }
     if (!empty($options['theme'])) {
         $this->setTheme($options['theme']);
     }
 }
Ejemplo n.º 5
0
 /**
  * Check if field passes validation
  *
  * @param string $values
  * @param string $valueKey
  * @param string $environment \Ip\Form::ENVIRONMENT_ADMIN or \Ip\Form::ENVIRONMENT_PUBLIC
  * @return bool
  */
 public function validate($values, $valueKey, $environment)
 {
     if (!empty($values[$valueKey]) && !preg_match('/^[-+]?[1-9]\\d*$/', $values[$valueKey])) {
         if ($environment == \Ip\Form::ENVIRONMENT_ADMIN) {
             return __('Integer required', 'Ip-admin', false);
         } else {
             return __('Integer required', 'Ip', false);
         }
     }
     return parent::validate($values, $valueKey, $environment);
 }
Ejemplo n.º 6
0
 /**
  * Check if field passes validation
  *
  * @param string $values
  * @param string $valueKey
  * @param string $environment \Ip\Form::ENVIRONMENT_ADMIN or \Ip\Form::ENVIRONMENT_PUBLIC
  * @return bool
  */
 public function validate($values, $valueKey, $environment)
 {
     if (!empty($values[$valueKey]) && !preg_match('/^[0-9]+(?:\\.[0-9]{0,2})?$/', $values[$valueKey])) {
         if ($environment == \Ip\Form::ENVIRONMENT_ADMIN) {
             return __('Please enter correct currency format. Eg. 10.50', 'Ip-admin', false);
         } else {
             return __('Please enter correct currency format. Eg. 10.50', 'Ip', false);
         }
     }
     return parent::validate($values, $valueKey, $environment);
 }
Ejemplo n.º 7
0
 /**
  * Constructor
  *
  * @param array $options
  */
 public function __construct($options = array())
 {
     $this->value = array();
     if (isset($options['values'])) {
         $this->values = $options['values'];
     } else {
         $this->values = array();
     }
     parent::__construct($options);
     $this->stolenId = $this->getAttribute('id');
     $this->removeAttribute('id');
 }
Ejemplo n.º 8
0
 /**
  * Constructor
  *
  * @param array $options
  */
 public function __construct($options = array())
 {
     if (isset($options['values'])) {
         $this->values = $options['values'];
     } else {
         $this->values = array();
     }
     parent::__construct($options);
     $this->stolenId = $this->getAttribute('id');
     $this->removeAttribute('id');
     // We need to put id only on the first input. So we will remove it from attributes list. And put it temporary to stolenId.
 }
Ejemplo n.º 9
0
 /**
  * Validate input value
  *
  * @param array $values all values of the form
  * @param string $valueKey key of value in values array that needs to be validated
  * @param \Ip\Form $environment
  * @return bool|string return string on error or false on success
  */
 public function validate($values, $valueKey, $environment)
 {
     if (preg_match('/^#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$\\b/', $values[$valueKey])) {
         return parent::validate($values, $valueKey, $environment);
     } else {
         if ($environment == \Ip\Form::ENVIRONMENT_ADMIN) {
             return __('Incorrect color code', 'Ip-admin', false);
         } else {
             return __('Incorrect color code', 'Ip', false);
         }
     }
 }
Ejemplo n.º 10
0
 /**
  * Validate if field passes validation
  *
  * @param array $values usually array of string. But some elements could be null or even array (eg. password confirmation field, or multiple file upload field).
  * @param string $valueKey This value key could not exist in values array.
  * @param string $environment \Ip\Form::ENVIRONMENT_ADMIN or \Ip\Form::ENVIRONMENT_PUBLIC
  * @return string Return string on error or false on success.
  */
 public function validate($values, $valueKey, $environment)
 {
     if (isset($values[$valueKey]['file']) && is_array($values[$valueKey]['file'])) {
         foreach ($values[$valueKey]['file'] as $file) {
             $uploadModel = \Ip\Internal\Repository\UploadModel::instance();
             if (!$uploadModel->isFileUploadedByCurrentUser($file, true)) {
                 if ($environment == \Ip\Form::ENVIRONMENT_ADMIN) {
                     $error = __('Session has ended. Please remove and re-upload files.', 'Ip-admin', false);
                 } else {
                     $error = __('Session has ended. Please remove and re-upload files.', 'Ip', false);
                 }
                 return $error;
             }
         }
     }
     return parent::validate($values, $valueKey, $environment);
 }
Ejemplo n.º 11
0
 public function __construct($options = array())
 {
     if (isset($options['fileLimit'])) {
         $this->fileLimit = $options['fileLimit'];
     }
     if (isset($options['preview'])) {
         $this->preview = $options['preview'];
     }
     if (isset($options['secure'])) {
         $this->secure = (bool) $options['secure'];
     }
     if (isset($options['path'])) {
         $this->path = $options['path'];
     }
     if (isset($options['filter'])) {
         $this->filter = $options['filter'];
     }
     if (isset($options['filterExtensions'])) {
         $this->filterExtensions = $options['filterExtensions'];
     }
     parent::__construct($options);
 }
Ejemplo n.º 12
0
 /**
  * Validate input value
  *
  * @param $values
  * @param $valueKey
  * @param $environment
  * @return string
  */
 public function validate($values, $valueKey, $environment)
 {
     if ($environment == \Ip\Form::ENVIRONMENT_ADMIN) {
         $errorText = __('The characters you entered didn\'t match', 'Ip-admin', false);
     } else {
         $errorText = __('The characters you entered didn\'t match', 'Ip', false);
     }
     if (!isset($values[$this->getName()]['id']) || !isset($values[$this->getName()]['code'])) {
         return $errorText;
     }
     $code = $values[$this->getName()]['code'];
     $id = $values[$this->getName()]['id'];
     $captcha = new \Ip\Lib\HnCaptcha\HnCaptcha($this->captchaInit, true);
     if (!isset($_SESSION['developer']['form']['field']['captcha'][$id]['public_key'])) {
         return $errorText;
     }
     $realCode = strtolower($captcha->generate_private($_SESSION['developer']['form']['field']['captcha'][$id]['public_key']));
     if (strtolower($code) !== $realCode) {
         return $errorText;
     }
     return parent::validate($values, $valueKey, $environment);
 }
Ejemplo n.º 13
0
 /**
  * Get validation attributes
  *
  * HTML5 spec: The first child option element of a select element with a required attribute and without a multiple attribute, and whose size is 1, must have either an empty value attribute, or must have no text content.
  * @see Ip\Form\Field.Field::getValidationAttributesStr()
  * @param string $doctype
  * @return string
  */
 public function getValidationAttributesStr($doctype)
 {
     $attributesStr = '';
     $values = $this->getValues();
     if (!isset($values[0])) {
         return parent::getValidationAttributesStr($doctype);
     }
     $firstValue = $values[0];
     if (is_array($firstValue)) {
         $key = $firstValue[0];
         $value = $firstValue[1];
     } else {
         $key = $firstValue;
         $value = $firstValue;
     }
     $html5Important = $doctype == \Ip\Response\Layout::DOCTYPE_HTML5 && $this->getAttribute('size') <= 1 && $this->getAttribute('multiple') === false && ($key != '' && $value != '');
     if (!$html5Important) {
         return parent::getValidationAttributesStr($doctype);
     }
     foreach ($this->getValidators() as $validator) {
         if (get_class($validator) == 'Ip\\Form\\Validator\\Required') {
             continue;
         }
         $tmpArgs = $validator->validatorAttributes();
         if ($tmpArgs != '') {
             $attributesStr .= ' ' . $tmpArgs;
         }
     }
     return $attributesStr;
 }
Ejemplo n.º 14
0
 /**
  * Set value
  *
  * @param string $value
  */
 public function setValue($value)
 {
     if ($value) {
         $this->setChecked(1);
     }
     parent::setValue($value);
 }
Ejemplo n.º 15
0
 /**
  * Constructor
  *
  * @param array $options
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     $this->addValidator('Email');
 }