Accueil > > > CLASSE FORM, GESTION DE VALIDATION POUR FORMULAIRE
CLASSE FORM, GESTION DE VALIDATION POUR FORMULAIRE
Information sur la source
Description
Une classe simple d'utilisation, qui permet de valider les données d'un formulaire et d'autoriser son envoi. - Personnalisation des messages pour chaque types d'erreurs détectés. - Gère les types : entiers, caractères ou selon vos attentes. - Gère l'upload de fichier : types mimes, extensions, taille fichier, téléchargement. - Utilisation des méthodes magiques, pour faciliter les accès aux données envoyés.
Source
- <?php
-
- /**
- * Form class,
- * Check fields and data validity
- * @category classes
- * @author PHPANONYME
- * @license GNU/LGPL
- */
-
- /* Exception Handling */
- class Form_Exception extends Exception { }
-
- class Form
- {
- /** @var array copy of $_POST or $_GET */
- public $_method;
-
- /** @var array copy of $_FILES */
- public $_file;
-
- /** @var array Save all errors of form */
- public $_controller;
-
-
- public function __construct($method)
- {
- $this->_method = array();
- $this->_controller = array();
- $this->_file = (!empty($_FILES)) ? $_FILES : '';
-
- if($method AND preg_match('/^(post|get)$/i', $method, $out))
- $this->_method = ($out[1]==strtolower('post')) ? $_POST : $_GET;
- else
- throw new Form_Exception('Indicate the method used, with \'post\' or \'get\'');
- }
-
- /**
- * Check if we can transmit form
- * @param string $key key value
- * @param string $message message error
- * @return boolean Validity is not ok
- */
- public function sendForm()
- {
- return (!empty($this->_method) AND empty($this->_controller)) ? TRUE : FALSE;
- }
-
- /**
- * Return errors or an error with key
- *
- * @param string $key key value
- * @param string $message message error
- * @return boolean Validity is not ok
- */
- public function getError($key = FALSE)
- {
- if($this->sendForm())
- return false;
- if(empty($this->_method))
- return false;
- if($key)
- return ($this->issetError($key)) ? $this->_controller[$key] : FALSE;
-
- return implode('<br/>', $this->_controller);
- }
-
- /**
- * Check if error exist with key
- * @param string $key key value
- * @return boolean Validity is not ok
- */
- public function issetError($key)
- {
- return (isset($this->_controller[$key]))? TRUE : FALSE;
- }
-
- /**
- * Save error with key
- * @param string $key key value
- * @param string $errorMessage message error
- * @return boolean Validity is not ok
- */
- public function setError($key, $errorMessage)
- {
- if(!empty($this->_controller[$key]))
- return false;
- if(is_array($errorMessage))
- $errorMessage = implode('<br/>', $errorMessage);
- return $this->_controller[$key] = strval($errorMessage);
- }
-
- //////////////////////////////////////////////////////
- // CONTROLLERS METHODS, used to control forms
- //////////////////////////////////////////////////////
-
-
- /**
- * Checks if key exists for methods 'post' or 'get'
- * @param string $key key value
- * @param string $message message error
- * @param boolean $returnError indicates the return type, only a boolean or not
- * @return boolean Validity is not ok
- */
- public function issetValue($key, $message=NULL, $returnError=TRUE)
- {
- if (is_array($key)) {
- foreach($key AS $keyof => $value) {
- if(isset($this->_method[$keyof]) AND empty($this->_method[$keyof]))
- $this->setError($keyof, $value);
- }
- return;
- }
- if($returnError)
- return (isset($this->_method[$key]) AND empty($this->_method[$key])) ? $this->setError($key, $message) : FALSE;
-
- return (isset($this->_method[$key]) AND !empty($this->_method[$key])) ? TRUE : FALSE;
- }
-
- /**
- * Checks if key exists for methods 'files'
- * @param string $key key value
- * @param string $message message error
- * @param boolean $returnError indicates the return type, only a boolean or not
- * @return boolean Validity is not ok
- */
- public function issetFile($key, $message=NULL, $returnError=TRUE)
- {
- if (is_array($key)) {
- foreach($key AS $keyof => $value) {
- if(isset($this->_file[$keyof]) AND empty($this->_file[$keyof]['name']))
- $this->setError($keyof, $value);
- }
- return;
- }
- if($returnError)
- return (isset($this->_file[$key]) AND empty($this->_file[$key]['name'])) ? $this->setError($key, $message) : FALSE;
-
- return (isset($this->_file[$key]) AND !empty($this->_file[$key]['name'])) ? TRUE : FALSE;
- }
-
- /**
- * Checks that these are only integers
- * @param string $key key value
- * @param string $message message error
- * @return boolean Validity is not ok
- */
- public function isInt($key, $message=NULL)
- {
- if (is_array($key)) {
- foreach($key AS $keyof => $value) {
- if(isset($this->_method[$keyof]) AND preg_match('/[^0-9]/', $this->_method[$keyof]))
- $this->setError($keyof, $value);
- }
- return;
- }
- return (isset($this->_method[$key]) AND preg_match('/[^0-9]/', $this->_method[$key])) ? $this->setError($key, $message) : FALSE;
- }
-
- /**
- * Checks that these are only characters
- * @param string $key key value
- * @param string $message message error
- * @return boolean Validity is not ok
- */
- public function isChar($key, $message = NULL)
- {
- if (is_array($key)) {
- foreach($key AS $keyof => $value) {
- if(isset($this->_method[$keyof]) AND preg_match('/[^a-z]/i', $this->_method[$keyof]))
- $this->setError($keyof, $value);
- }
- return;
- }
- return (isset($this->_method[$key]) AND preg_match('/[^a-z]/i', $this->_method[$key])) ? $this->setError($key, $message) : FALSE;
- }
-
- /**
- * Checks validity for email
- * @param string $key key value
- * @param string $message message error
- * @return boolean Validity is not ok
- */
- public function isEmail($key, $message=NULL)
- {
- $pattern = '/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/';
- if (is_array($key)) {
- foreach($key AS $keyof => $value) {
- if(isset($this->_method[$keyof]) AND !preg_match($pattern, $this->_method[$keyof]))
- $this->setError($keyof, $value);
- }
- return;
- }
- return (isset($this->_method[$key]) AND !preg_match($pattern, $this->_method[$key])) ? $this->setError($key, $message) : FALSE;
- }
-
- /**
- * Checks the validity with a custom type
- * @param string $key key value
- * @param string $rules pattern customize
- * @param string $message message error
- * @return boolean Validity is not ok
- */
- public function isExtendType($key, $rules, $message=NULL)
- {
- if (is_array($key)) {
- foreach($key AS $keyof => $value) {
- if(isset($this->_method[$keyof]) AND preg_match($rules, $this->_method[$keyof]))
- $this->setError($keyof, $value);
- }
- return;
- }
- return (isset($this->_method[$key]) AND preg_match($rules, $this->_method[$key])) ? $this->setError($key, $message) : FALSE;
- }
-
- public function isNotExtendType($key, $rules, $message=NULL)
- {
- if (is_array($key)) {
- foreach($key AS $keyof => $value) {
- if(isset($this->_method[$keyof]) AND !preg_match($rules, $this->_method[$keyof]))
- $this->setError($keyof, $value);
- }
- return;
- }
- return (isset($this->_method[$key]) AND !preg_match($rules, $this->_method[$key])) ? $this->setError($key, $message) : FALSE;
- }
-
- /**
- * Verifies that a file has been transmitted
- * @param string $key key value
- * @param string $message message error
- * @return boolean Validity is not ok
- */
- public function isFileTransmit($key, $message=NULL)
- {
- if (is_array($key))
- throw new Form_Exception('Do not use tables');
- if(empty($this->_file[$key]))
- return false;
-
- $value = $this->issetFile($key, '', FALSE);
- return ($value AND ($this->_file[$key]['error']!=UPLOAD_ERR_OK OR !is_uploaded_file($this->_file[$key]['tmp_name'])) ) ? $this->setError($key, $message) : FALSE;
- }
-
- /**
- * Checks the validity of the extension for file
- * @param string $key key value
- * @param string or array $extensions extension file
- * @param string $message message error
- * @return boolean Validity is not ok
- */
- public function isFileExtensions($key, $extensions, $message=NULL)
- {
- if (is_array($key))
- throw new Form_Exception('Do not use tables');
- if(is_array($extensions))
- $extensions = implode('|', $extensions);
-
- $value = $this->issetFile($key, '', FALSE);
- return ($value AND !preg_match('/('.$extensions.')$/i', $this->_file[$key]['name'])) ? $this->setError($key, $message) : FALSE;
- }
-
- /**
- * Checks the validity of the mime type for file
- * @param string $key key value
- * @param string or array $mimes mime type
- * @param string $message message error
- * @return boolean Validity is not ok
- */
- public function isFileMimes($key, $mimes, $message=NULL)
- {
- if (is_array($key))
- throw new Form_Exception('Do not use tables');
- if(is_array($mimes))
- $mimes = implode('|', $mimes);
-
- $value = $this->issetFile($key, '', FALSE);
- if(version_compare(substr(phpversion(), 0, 3), '5.3.0') >= 0 OR !class_exists('finfo', false))
- return ($value AND !preg_match('#^('.$mimes.')$#i', $this->_file[$key]['type'])) ? $this->setError($key, $message) : FALSE;
- elseif($value) {
- $finfo = new finfo;
- $realmime = $finfo->file($this->_file[$key]['tmp_name'], FILEINFO_MIME_TYPE);
- return (!preg_match('#^('.$mimes.')$#i', $realmime)) ? $this->setError($key, $message) : FALSE;
- }
- return false;
- }
-
- /**
- * Checks the validity of the size for file
- * @param string $key key value
- * @param int $size size file in octet
- * @param string $message message error
- * @return boolean Validity is not ok
- */
- public function isFileSize($key, $size, $message=NULL)
- {
- if (is_array($key) OR is_array($size))
- throw new Form_Exception('Do not use tables');
- if(preg_match('/[^0-9]/', $size))
- throw new Form_Exception('Use only int values');
-
- $value = $this->issetFile($key, '', FALSE);
- return ($value AND $size<=$this->_file[$key]['size']) ? $this->setError($key, $message) : FALSE;
- }
-
- /**
- * Checks the validity of comparing values
- * @param string $key key value
- * @param string $message message error
- * @return boolean Validity is not ok
- */
- public function compareValue($key, $value1, $value2, $sign=FALSE, $message=NULL)
- {
- $issetKey = $this->issetValue($key, '', FALSE);
-
- if(is_array($key))
- throw new Form_Exception('Do not use tables');
- if(is_array($value1) AND is_array($value2))
- throw new Form_Exception('Only one of the two values may be in the form of a table');
- if(!isset($value1) AND !isset($value2))
- throw new Form_Exception('Indicate two values to compare');
- if($sign AND !preg_match('/^(===|==|<=|>=|<>|!=|!==|<|>)$/', $sign))
- throw new Form_Exception('Specify valid comparison operators');
-
- // Operating
- if(is_array($value1) AND !is_array($value2)){
- $value1 = implode('|', $value1);
- return ($issetKey AND preg_match('/^('.$value1.')$/', $value2)) ? FALSE : $this->setError($key, $message);
- }
- elseif(!is_array($value1) AND is_array($value2)){
- $value2 = implode('|', $value2);
- return ($issetKey AND preg_match('/^('.$value2.')$/', $value1)) ? FALSE : $this->setError($key, $message);
- }
- elseif(empty($sign)) {
- return ($issetKey AND preg_match('/^('.$value1.')$/', $value2)) ? FALSE : $this->setError($key, $message);
- }
- else {
- $comparate = Form::getComparison($value1, $value2, $sign);
- return ($issetKey AND !$comparate) ? FALSE : $this->setError($key, $message);
- }
- }
-
- //////////////////////////////////////////////////////
- // MAGICS METHODS
- //////////////////////////////////////////////////////
-
- public function __get($key)
- {
- if(isset($this->_method[$key]))
- return $this->_method[$key];
- elseif(isset($this->_file[$key]))
- return $this->_file[$key]['name'];
- else
- return false;
- }
-
- public function __isset($key)
- {
- if(isset($this->_method[$key]))
- return isset($this->_method[$key]);
- elseif(isset($this->_file[$key]))
- return isset($this->_file[$key]);
- }
-
- public function __unset($key)
- {
- if(isset($this->_method[$key]))
- unset($this->_method[$key]);
- if(isset($this->_file[$key]))
- unset($this->_file[$key]);
- }
-
- //////////////////////////////////////////////////////
- // STATICS METHODS
- //////////////////////////////////////////////////////
-
- public static function getComparison($value1, $value2, $sign)
- {
- switch($sign) {
- case '===' : return ($value1===$value2) ? TRUE : FALSE;
- break;
- case '!==' : return ($value1!==$value2) ? TRUE : FALSE;
- break;
- case '==' : return ($value1==$value2) ? TRUE : FALSE;
- break;
- case '<=' : return ($value1<=$value2) ? TRUE : FALSE;
- break;
- case '>=' : return ($value1>=$value2) ? TRUE : FALSE;
- break;
- case '<>' :
- case '!=' : return ($value1!=$value2) ? TRUE : FALSE;
- break;
- case '<' : return ($value1<$value2) ? TRUE : FALSE;
- break;
- case '>' : return ($value1>$value2) ? TRUE : FALSE;
- break;
- }
- }
-
- }
-
- ?>
-
<?php
/**
* Form class,
* Check fields and data validity
* @category classes
* @author PHPANONYME
* @license GNU/LGPL
*/
/* Exception Handling */
class Form_Exception extends Exception { }
class Form
{
/** @var array copy of $_POST or $_GET */
public $_method;
/** @var array copy of $_FILES */
public $_file;
/** @var array Save all errors of form */
public $_controller;
public function __construct($method)
{
$this->_method = array();
$this->_controller = array();
$this->_file = (!empty($_FILES)) ? $_FILES : '';
if($method AND preg_match('/^(post|get)$/i', $method, $out))
$this->_method = ($out[1]==strtolower('post')) ? $_POST : $_GET;
else
throw new Form_Exception('Indicate the method used, with \'post\' or \'get\'');
}
/**
* Check if we can transmit form
* @param string $key key value
* @param string $message message error
* @return boolean Validity is not ok
*/
public function sendForm()
{
return (!empty($this->_method) AND empty($this->_controller)) ? TRUE : FALSE;
}
/**
* Return errors or an error with key
*
* @param string $key key value
* @param string $message message error
* @return boolean Validity is not ok
*/
public function getError($key = FALSE)
{
if($this->sendForm())
return false;
if(empty($this->_method))
return false;
if($key)
return ($this->issetError($key)) ? $this->_controller[$key] : FALSE;
return implode('<br/>', $this->_controller);
}
/**
* Check if error exist with key
* @param string $key key value
* @return boolean Validity is not ok
*/
public function issetError($key)
{
return (isset($this->_controller[$key]))? TRUE : FALSE;
}
/**
* Save error with key
* @param string $key key value
* @param string $errorMessage message error
* @return boolean Validity is not ok
*/
public function setError($key, $errorMessage)
{
if(!empty($this->_controller[$key]))
return false;
if(is_array($errorMessage))
$errorMessage = implode('<br/>', $errorMessage);
return $this->_controller[$key] = strval($errorMessage);
}
//////////////////////////////////////////////////////
// CONTROLLERS METHODS, used to control forms
//////////////////////////////////////////////////////
/**
* Checks if key exists for methods 'post' or 'get'
* @param string $key key value
* @param string $message message error
* @param boolean $returnError indicates the return type, only a boolean or not
* @return boolean Validity is not ok
*/
public function issetValue($key, $message=NULL, $returnError=TRUE)
{
if (is_array($key)) {
foreach($key AS $keyof => $value) {
if(isset($this->_method[$keyof]) AND empty($this->_method[$keyof]))
$this->setError($keyof, $value);
}
return;
}
if($returnError)
return (isset($this->_method[$key]) AND empty($this->_method[$key])) ? $this->setError($key, $message) : FALSE;
return (isset($this->_method[$key]) AND !empty($this->_method[$key])) ? TRUE : FALSE;
}
/**
* Checks if key exists for methods 'files'
* @param string $key key value
* @param string $message message error
* @param boolean $returnError indicates the return type, only a boolean or not
* @return boolean Validity is not ok
*/
public function issetFile($key, $message=NULL, $returnError=TRUE)
{
if (is_array($key)) {
foreach($key AS $keyof => $value) {
if(isset($this->_file[$keyof]) AND empty($this->_file[$keyof]['name']))
$this->setError($keyof, $value);
}
return;
}
if($returnError)
return (isset($this->_file[$key]) AND empty($this->_file[$key]['name'])) ? $this->setError($key, $message) : FALSE;
return (isset($this->_file[$key]) AND !empty($this->_file[$key]['name'])) ? TRUE : FALSE;
}
/**
* Checks that these are only integers
* @param string $key key value
* @param string $message message error
* @return boolean Validity is not ok
*/
public function isInt($key, $message=NULL)
{
if (is_array($key)) {
foreach($key AS $keyof => $value) {
if(isset($this->_method[$keyof]) AND preg_match('/[^0-9]/', $this->_method[$keyof]))
$this->setError($keyof, $value);
}
return;
}
return (isset($this->_method[$key]) AND preg_match('/[^0-9]/', $this->_method[$key])) ? $this->setError($key, $message) : FALSE;
}
/**
* Checks that these are only characters
* @param string $key key value
* @param string $message message error
* @return boolean Validity is not ok
*/
public function isChar($key, $message = NULL)
{
if (is_array($key)) {
foreach($key AS $keyof => $value) {
if(isset($this->_method[$keyof]) AND preg_match('/[^a-z]/i', $this->_method[$keyof]))
$this->setError($keyof, $value);
}
return;
}
return (isset($this->_method[$key]) AND preg_match('/[^a-z]/i', $this->_method[$key])) ? $this->setError($key, $message) : FALSE;
}
/**
* Checks validity for email
* @param string $key key value
* @param string $message message error
* @return boolean Validity is not ok
*/
public function isEmail($key, $message=NULL)
{
$pattern = '/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/';
if (is_array($key)) {
foreach($key AS $keyof => $value) {
if(isset($this->_method[$keyof]) AND !preg_match($pattern, $this->_method[$keyof]))
$this->setError($keyof, $value);
}
return;
}
return (isset($this->_method[$key]) AND !preg_match($pattern, $this->_method[$key])) ? $this->setError($key, $message) : FALSE;
}
/**
* Checks the validity with a custom type
* @param string $key key value
* @param string $rules pattern customize
* @param string $message message error
* @return boolean Validity is not ok
*/
public function isExtendType($key, $rules, $message=NULL)
{
if (is_array($key)) {
foreach($key AS $keyof => $value) {
if(isset($this->_method[$keyof]) AND preg_match($rules, $this->_method[$keyof]))
$this->setError($keyof, $value);
}
return;
}
return (isset($this->_method[$key]) AND preg_match($rules, $this->_method[$key])) ? $this->setError($key, $message) : FALSE;
}
public function isNotExtendType($key, $rules, $message=NULL)
{
if (is_array($key)) {
foreach($key AS $keyof => $value) {
if(isset($this->_method[$keyof]) AND !preg_match($rules, $this->_method[$keyof]))
$this->setError($keyof, $value);
}
return;
}
return (isset($this->_method[$key]) AND !preg_match($rules, $this->_method[$key])) ? $this->setError($key, $message) : FALSE;
}
/**
* Verifies that a file has been transmitted
* @param string $key key value
* @param string $message message error
* @return boolean Validity is not ok
*/
public function isFileTransmit($key, $message=NULL)
{
if (is_array($key))
throw new Form_Exception('Do not use tables');
if(empty($this->_file[$key]))
return false;
$value = $this->issetFile($key, '', FALSE);
return ($value AND ($this->_file[$key]['error']!=UPLOAD_ERR_OK OR !is_uploaded_file($this->_file[$key]['tmp_name'])) ) ? $this->setError($key, $message) : FALSE;
}
/**
* Checks the validity of the extension for file
* @param string $key key value
* @param string or array $extensions extension file
* @param string $message message error
* @return boolean Validity is not ok
*/
public function isFileExtensions($key, $extensions, $message=NULL)
{
if (is_array($key))
throw new Form_Exception('Do not use tables');
if(is_array($extensions))
$extensions = implode('|', $extensions);
$value = $this->issetFile($key, '', FALSE);
return ($value AND !preg_match('/('.$extensions.')$/i', $this->_file[$key]['name'])) ? $this->setError($key, $message) : FALSE;
}
/**
* Checks the validity of the mime type for file
* @param string $key key value
* @param string or array $mimes mime type
* @param string $message message error
* @return boolean Validity is not ok
*/
public function isFileMimes($key, $mimes, $message=NULL)
{
if (is_array($key))
throw new Form_Exception('Do not use tables');
if(is_array($mimes))
$mimes = implode('|', $mimes);
$value = $this->issetFile($key, '', FALSE);
if(version_compare(substr(phpversion(), 0, 3), '5.3.0') >= 0 OR !class_exists('finfo', false))
return ($value AND !preg_match('#^('.$mimes.')$#i', $this->_file[$key]['type'])) ? $this->setError($key, $message) : FALSE;
elseif($value) {
$finfo = new finfo;
$realmime = $finfo->file($this->_file[$key]['tmp_name'], FILEINFO_MIME_TYPE);
return (!preg_match('#^('.$mimes.')$#i', $realmime)) ? $this->setError($key, $message) : FALSE;
}
return false;
}
/**
* Checks the validity of the size for file
* @param string $key key value
* @param int $size size file in octet
* @param string $message message error
* @return boolean Validity is not ok
*/
public function isFileSize($key, $size, $message=NULL)
{
if (is_array($key) OR is_array($size))
throw new Form_Exception('Do not use tables');
if(preg_match('/[^0-9]/', $size))
throw new Form_Exception('Use only int values');
$value = $this->issetFile($key, '', FALSE);
return ($value AND $size<=$this->_file[$key]['size']) ? $this->setError($key, $message) : FALSE;
}
/**
* Checks the validity of comparing values
* @param string $key key value
* @param string $message message error
* @return boolean Validity is not ok
*/
public function compareValue($key, $value1, $value2, $sign=FALSE, $message=NULL)
{
$issetKey = $this->issetValue($key, '', FALSE);
if(is_array($key))
throw new Form_Exception('Do not use tables');
if(is_array($value1) AND is_array($value2))
throw new Form_Exception('Only one of the two values may be in the form of a table');
if(!isset($value1) AND !isset($value2))
throw new Form_Exception('Indicate two values to compare');
if($sign AND !preg_match('/^(===|==|<=|>=|<>|!=|!==|<|>)$/', $sign))
throw new Form_Exception('Specify valid comparison operators');
// Operating
if(is_array($value1) AND !is_array($value2)){
$value1 = implode('|', $value1);
return ($issetKey AND preg_match('/^('.$value1.')$/', $value2)) ? FALSE : $this->setError($key, $message);
}
elseif(!is_array($value1) AND is_array($value2)){
$value2 = implode('|', $value2);
return ($issetKey AND preg_match('/^('.$value2.')$/', $value1)) ? FALSE : $this->setError($key, $message);
}
elseif(empty($sign)) {
return ($issetKey AND preg_match('/^('.$value1.')$/', $value2)) ? FALSE : $this->setError($key, $message);
}
else {
$comparate = Form::getComparison($value1, $value2, $sign);
return ($issetKey AND !$comparate) ? FALSE : $this->setError($key, $message);
}
}
//////////////////////////////////////////////////////
// MAGICS METHODS
//////////////////////////////////////////////////////
public function __get($key)
{
if(isset($this->_method[$key]))
return $this->_method[$key];
elseif(isset($this->_file[$key]))
return $this->_file[$key]['name'];
else
return false;
}
public function __isset($key)
{
if(isset($this->_method[$key]))
return isset($this->_method[$key]);
elseif(isset($this->_file[$key]))
return isset($this->_file[$key]);
}
public function __unset($key)
{
if(isset($this->_method[$key]))
unset($this->_method[$key]);
if(isset($this->_file[$key]))
unset($this->_file[$key]);
}
//////////////////////////////////////////////////////
// STATICS METHODS
//////////////////////////////////////////////////////
public static function getComparison($value1, $value2, $sign)
{
switch($sign) {
case '===' : return ($value1===$value2) ? TRUE : FALSE;
break;
case '!==' : return ($value1!==$value2) ? TRUE : FALSE;
break;
case '==' : return ($value1==$value2) ? TRUE : FALSE;
break;
case '<=' : return ($value1<=$value2) ? TRUE : FALSE;
break;
case '>=' : return ($value1>=$value2) ? TRUE : FALSE;
break;
case '<>' :
case '!=' : return ($value1!=$value2) ? TRUE : FALSE;
break;
case '<' : return ($value1<$value2) ? TRUE : FALSE;
break;
case '>' : return ($value1>$value2) ? TRUE : FALSE;
break;
}
}
}
?>
Historique
- 11 octobre 2010 02:07:45 :
- Ajout gestion validation d'upload
- 11 octobre 2010 02:10:53 :
- -------------------
- 11 octobre 2010 21:52:06 :
- -----------------
- 12 octobre 2010 20:45:37 :
- Correction de certaines choses et ajout d'un paramètre
- 18 octobre 2010 05:59:40 :
- Réécriture en partie des classes, de la documentation, et des commentaires
- 18 octobre 2010 16:46:26 :
- ---
- 18 octobre 2010 18:42:17 :
- Ouppps !!! correction d'un léger souci d'initialisation de la variable LockForm, qui empêchait la validation du formulaire en cas de succès.
- 14 décembre 2010 01:18:37 :
- Réécriture COMPLETE de la classe, suite à certaines restrictions de l'ancienne version et son manque de permissivité d'évolution.
- 15 décembre 2010 18:05:47 :
- correction bugs
- 29 mars 2011 16:32:55 :
- - Correction de bugs et, correction/changement de certaines variables
- 29 mars 2011 18:09:12 :
- del zip
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
champs formulaire obligatoire [ par Blacknight91titi ]
Salutvoila j'aimerai savoir comment faire pour que dans un formulaire on soit obliger de remplir certain champs, et si un parmis eu n'est pas rempli a
Prob de redirection et validation [ par LeManchot ]
Voila jai encoren un souci:jai un formulaire que je valide via un bouton (pr linstant ok) mais par ce meme bouton je dois rediriger la page ou se toru
Prob Debutant - Validation d'1 formulaire par Menu Déroulant . [ par marcooo ]
Bonjour a tous .J'esplique le problème ... Tout d'abord je tien a dire ke je débute dans le PHP/MySQL.Alors voila, je voudrai créer une sorte de moteu
Validation Formulaire [ par kiboumz ]
Bonjour, J'ai crée un formulaire duquel j'envoie des données vers une base de données, cependant j'aimerais pouvoir valider mes donn&
Problème de validation de formulaire [ par ehmarc ]
Hello world!!!Bon j'ai un petit problème jai formulaire tres simple une case identification un bouton envoyerj'arrive à m'identifier nickel quand quan
Double envoie lors d'une validation de formulaire? [ par Monico9385 ]
Bonjour à tous, j'ai un petit soucis concernant un double envoie lors de la validation d'un formulaire, je m'explique : j'ai sur un site un for
Activation d'un compte par mail [ par aissiou1979 ]
Voila.J'ai realisé un formulaire d'inscription pour jouer à un concours.A la suite de la validation de ce formulaire un mail est envoyé à la personne
validation de courriel [ par luciano12 ]
Bonjour,J'aurais besoin de votre aide pour m'aider à faire la chose suivante:Je voudrais que les visiteurs qui visitent mon site Intenret puissent rem
Balise select liées [ par nagrom_om ]
Salut, Voila mon probleme : J'ai une page dans laquelle il y a une balise select qui affiche une liste d'éléments, le choix d un élément provoque l af
CLASS PERMETTANT DE CRÉER UNE IMAGE POUR LA VALIDATION D'UN FORMULAIRE [ par Tanaka56 ]
Bonjour à tous.<br style="mso
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
GOOGLE MAPGOOGLE MAP par fatmanajjar
Cliquez pour lire la suite par fatmanajjar
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|