public function clean($value) { parent::clean($value); $out = null; foreach ($this->input_formats as $format) { if (false !== ($date = strptime($value, $format))) { $day = str_pad($date['tm_mday'], 2, '0', STR_PAD_LEFT); $month = str_pad($date['tm_mon'] + 1, 2, '0', STR_PAD_LEFT); $year = str_pad($date['tm_year'] + 1900, 4, '0', STR_PAD_LEFT); $h = str_pad($date['tm_hour'], 2, '0', STR_PAD_LEFT); $m = str_pad($date['tm_min'], 2, '0', STR_PAD_LEFT); $s = $date['tm_sec']; if ($s > 59) { $s = 59; } $s = str_pad($s, 2, '0', STR_PAD_LEFT); $out = $year . '-' . $month . '-' . $day . ' ' . $h . ':' . $m . ':' . $s; break; } } if ($out !== null) { // We internally use GMT, so we convert it to a GMT date. return gmdate('Y-m-d H:i:s', strtotime($out)); } throw new Pluf_Form_Invalid(__('Enter a valid date/time.')); }
public function clean($value) { parent::clean($value); if (in_array($value, $this->empty_values)) { return ''; } if (!Pluf_Utils::isValidUrl($value)) { throw new Pluf_Form_Invalid(__('Enter a valid address.')); } return $value; }
/** * Validate some possible input for the field. * * @param mixed Input * @return string Path to the file relative to 'upload_path' */ function clean($value) { parent::clean($value); if (is_null($value) and !$this->required) { return ''; // no file } elseif (is_null($value) and $this->required) { throw new Pluf_Form_Invalid(__('No files were uploaded. Please try to send the file again.')); } $errors = array(); $no_files = false; switch ($value['error']) { case UPLOAD_ERR_OK: break; case UPLOAD_ERR_INI_SIZE: throw new Pluf_Form_Invalid(sprintf(__('The uploaded file is too large. Reduce the size of the file to %s and send it again.'), Pluf_Utils::prettySize(ini_get('upload_max_filesize')))); break; case UPLOAD_ERR_FORM_SIZE: throw new Pluf_Form_Invalid(sprintf(__('The uploaded file is too large. Reduce the size of the file to %s and send it again.'), Pluf_Utils::prettySize($_REQUEST['MAX_FILE_SIZE']))); break; case UPLOAD_ERR_PARTIAL: throw new Pluf_Form_Invalid(__('The upload did not complete. Please try to send the file again.')); break; case UPLOAD_ERR_NO_FILE: if ($this->required) { throw new Pluf_Form_Invalid(__('No files were uploaded. Please try to send the file again.')); } else { return ''; // no file } break; case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_CANT_WRITE: throw new Pluf_Form_Invalid(__('The server has no temporary folder correctly configured to store the uploaded file.')); break; case UPLOAD_ERR_EXTENSION: throw new Pluf_Form_Invalid(__('The uploaded file has been stopped by an extension.')); break; default: throw new Pluf_Form_Invalid(__('An error occured when upload the file. Please try to send the file again.')); } if ($value['size'] > $this->max_size) { throw new Pluf_Form_Invalid(sprintf(__('The uploaded file is to big (%1$s). Reduce the size to less than %2$s and try again.'), Pluf_Utils::prettySize($value['size']), Pluf_Utils::prettySize($this->max_size))); } // copy the file to the final destination and updated $value // with the final path name. 'final_name' is relative to // Pluf::f('upload_path') Pluf::loadFunction($this->move_function); // Should throw a Pluf_Form_Invalid exception if error or the // value to be stored in the database. return call_user_func($this->move_function, $value, $this->move_function_params); }
public function clean($value) { parent::clean($value); foreach ($this->input_formats as $format) { if (false !== ($date = strptime($value, $format))) { $day = str_pad($date['tm_mday'], 2, '0', STR_PAD_LEFT); $month = str_pad($date['tm_mon'] + 1, 2, '0', STR_PAD_LEFT); $year = str_pad($date['tm_year'] + 1900, 4, '0', STR_PAD_LEFT); return $year . '-' . $month . '-' . $day; } } throw new Pluf_Form_Invalid(__('Enter a valid date.')); }
public function clean($value) { parent::clean($value); if (in_array($value, $this->empty_values)) { $value = ''; } $value_length = mb_strlen($value); if ($this->max_length !== null and $value_length > $this->max_length) { throw new Pluf_Form_Invalid(sprintf(__('Ensure this value has at most %1$d characters (it has %2$d).'), $this->max_length, $value_length)); } if ($this->min_length !== null and $value_length < $this->min_length) { throw new Pluf_Form_Invalid(sprintf(__('Ensure this value has at least %1$d characters (it has %2$d).'), $this->min_length, $value_length)); } return $value; }
/** * Removes any character not allowed and valid the size of the field. * * @see Pluf_Form_Field::clean() * @throws Pluf_Form_Invalid If the lenght of the field has not a valid size. */ public function clean($value) { parent::clean($value); if ($value) { $value = Pluf_DB_Field_Slug::slugify($value); $len = mb_strlen($value, Pluf::f('encoding', 'UTF-8')); if ($this->max_size < $len) { throw new Pluf_Form_Invalid(sprintf($this->_error_messages['max_size'], $this->max_size, $len)); } if ($this->min_size > $len) { throw new Pluf_Form_Invalid(sprintf($this->_error_messages['min_size'], $this->min_size, $len)); } } else { $value = ''; } return $value; }
public function clean($value) { parent::clean($value); if (in_array($value, $this->empty_values)) { $value = ''; } if ($value == '') { return $value; } $emails = preg_split('/\\s*,\\s*/', $value, -1, PREG_SPLIT_NO_EMPTY); foreach ($emails as $email) { if (!Pluf_Utils::isValidEmail($email)) { throw new Pluf_Form_Invalid(__('Please enter one or more valid email addresses.')); } } return implode(',', $emails); }
public function clean($value) { parent::clean($value); $value = $this->setDefaultEmpty($value); if ($this->multiple) { return $this->multiClean($value); } else { if ($value == '') { return $value; } if (!preg_match('/^[\\+\\-]?[0-9]+$/', $value)) { throw new Pluf_Form_Invalid(__('The value must be an integer.')); } $this->checkMinMax($value); } return (int) $value; }
public function clean($value) { parent::clean($value); if (in_array($value, $this->empty_values)) { return ''; } foreach ($this->input_formats as $format) { if (false !== ($date = strptime($value, $format))) { $day = $date['tm_mday']; $month = $date['tm_mon'] + 1; $year = $date['tm_year'] + 1900; if (checkdate($month, $day, $year)) { return str_pad($year, 4, '0', STR_PAD_LEFT) . '-' . str_pad($month, 2, '0', STR_PAD_LEFT) . '-' . str_pad($day, 2, '0', STR_PAD_LEFT); } } } throw new Pluf_Form_Invalid(__('Enter a valid date.')); }
public function clean($value) { parent::clean($value); if (in_array($value, $this->empty_values)) { $value = ''; } if (!is_numeric($value)) { throw new Pluf_Form_Invalid(__('Enter a number.')); } $value = (double) $value; if ($this->max_value !== null and $this->max_value < $value) { throw new Pluf_Form_Invalid(sprintf(__('Ensure this value is less than or equal to %s.'), $this->max_value)); } if ($this->min_value !== null and $this->min_value > $value) { throw new Pluf_Form_Invalid(sprintf(__('Ensure this value is greater than or equal to %s.'), $this->min_value)); } return $value; }
public function clean($value) { parent::clean($value); if (in_array($value, $this->empty_values)) { return ''; } foreach ($this->input_formats as $format) { if (false !== ($date = strptime($value, $format))) { $day = $date['tm_mday']; $month = $date['tm_mon'] + 1; $year = $date['tm_year'] + 1900; // PHP's strptime has various quirks, e.g. it doesn't check // gregorian dates for validity and it also allows '60' in // the seconds part if (checkdate($month, $day, $year) && $date['tm_sec'] < 60) { $date = str_pad($year, 4, '0', STR_PAD_LEFT) . '-' . str_pad($month, 2, '0', STR_PAD_LEFT) . '-' . str_pad($day, 2, '0', STR_PAD_LEFT) . ' ' . str_pad($date['tm_hour'], 2, '0', STR_PAD_LEFT) . ':' . str_pad($date['tm_min'], 2, '0', STR_PAD_LEFT) . ':'; str_pad($date['tm_sec'], 2, '0', STD_PAD_LEFT); // we internally use GMT, so we convert it to a GMT date. return gmdate('Y-m-d H:i:s', strtotime($date)); } } } throw new Pluf_Form_Invalid(__('Enter a valid date/time.')); }