Example #1
0
 /**
  * Validates the input value according to this attribute
  *
  * @param InputInterface $input The input to validate
  *
  * @return string|true True if its valid, string with the error if not
  */
 public static function validate($input)
 {
     $value = $input->val();
     //File
     if ($input->attr('type') === 'file') {
         $value = isset($value['name']) ? $value['name'] : null;
     }
     $attr = str_replace('/', '\\/', $input->attr('pattern'));
     return empty($attr) || empty($value) || filter_var($value, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => "/^{$attr}\$/"))) ? true : sprintf(static::$error_message, $attr);
 }
Example #2
0
 /**
  * Callback used on add this attribute to an input
  *
  * @param InputInterface $input The input in which the attribute will be added
  * @param mixed          $value The value of this attribute
  *
  * @return mixed $value The value sanitized
  */
 public static function onAdd($input, $value)
 {
     if (!is_bool($value)) {
         throw new \InvalidArgumentException('The multiple value must be a boolean');
     }
     if ($value && ($name = $input->attr('name')) && substr($name, -2) !== '[]') {
         $input->attr('name', $name . '[]');
     }
     return $value;
 }
Example #3
0
 /**
  * Validates the input value according to this attribute
  *
  * @param InputInterface $input The input to validate
  *
  * @return string|true True if its valid, string with the error if not
  */
 public static function validate($input)
 {
     $value = $input->val();
     //File
     if ($input->attr('type') === 'file') {
         $value = isset($value['name']) && !empty($value['size']) ? $value['name'] : null;
     }
     $attr = $input->attr('required');
     return empty($attr) || !empty($value) || strlen($value) > 0 ? true : sprintf(static::$error_message, $attr);
 }
Example #4
0
 /**
  * Callback used on add this attribute to an input
  *
  * @param InputInterface $input The input in which the attribute will be added
  * @param mixed          $value The value of this attribute
  *
  * @return mixed $value The value sanitized
  */
 public static function onAdd($input, $value)
 {
     if ($input->attr('multiple') && substr($value, -2) !== '[]') {
         $value .= '[]';
     }
     return $value;
 }
Example #5
0
 /**
  * Validates the input value according to this attribute
  *
  * @param InputInterface $input The input to validate
  *
  * @return string|true True if its valid, string with the error if not
  */
 public static function validate($input)
 {
     $value = $input->val();
     $attr = $input->attr('min');
     return strlen($value) === 0 || $value >= $attr ? true : sprintf(static::$error_message, $attr);
 }
Example #6
0
 /**
  * Validates the input value according to this attribute
  *
  * @param InputInterface $input The input to validate
  *
  * @return string|true True if its valid, string with the error if not
  */
 public static function validate($input)
 {
     $value = $input->val();
     $attr = $input->attr('maxlength');
     return empty($attr) || strlen($value) <= $attr ? true : sprintf(static::$error_message, $attr);
 }