Source for file form.class.php
Documentation is available at form.class.php
* @package Template Engine
protected $msg_err =
array(); // Array of error messages
protected $last_obj =
''; // the last object on parameter
protected $objError =
array(); // array of error object / allows to indicate them in javascript
protected $objErrorMsg =
array(); // array of errors for a possible customisation
protected $custom_msg =
''; // Personalize the errors messages
protected $formErrorLang =
TPLN_LANG; // recover the language per defect
protected $formName =
''; // name of formulaire per defect
protected $init =
0; // initialize data of the formulaire ?
protected $row_val =
array(); // contains the array of values
protected $captcha =
0; // captcha activated
* @var string Form error color
* Return formatted message
* @param array $parameters
public function getMessage($index, $parameters=
array())
if(count($parameters) >
0)
if(TPLN_OUTPUT_CHARSET !=
'utf-8')
* rewrite a new name object
* @param array $objects_name
* get the new name of the object
* This method allows you to chose the place of form error messages T:
* display messages on top (bloc form_error obliged) I (by default): display messages below html widget
* This method allows you to modify form name.
* @param string $formName
* this method tests if there is personalized message error
* customize error message
// recover the objects of error for the signals in javascript
* Verify if treatment protection has be done
public function rules($obj)
// apply htmlentites to protect data
// pull out the [] which is array
if(substr($obj2, -
2, 2) ==
'[]')
if(!isset
($_POST[$obj2]))
$_POST[$obj2] =
array(); #avoid the bugs IE, FIREFOX
$_POST[$obj2] =
''; #avoid the bugs IE, FIREFOX
// if($this->formErrorLang == 'fr')
// die("TPLN Form: `$obj` Aucun objet trouvé");
// die("TPLN Form: `$obj` No object found");
//die($this->getMessage(0, array($obj_name)));
return false; # obligatory
* This method initializes data of HTML form by convertion of php parameter.
* It is usefull for editing a record of a table.
* this method allows you to record an error message
* which will be posted with the next error.
public function setMessage($msg) // personalize an error message
if(TPLN_OUTPUT_CHARSET ==
'utf-8')
* this method allows you to ckeck if the object isn't empty.
* If that's the case then alarm error is started.
public function notEmpty($obj =
'', $msg=
'') // check if the object isn't empty
foreach($obj as $cur_obj)
if(!$this->rules($obj))return;
// if notEmpty is used on file objet then fileControl will be called instead
// Tow diffrents treantments for arrays and the others types
elseif(count($_POST[$obj2]) ==
0)
//$msg = "Field '$this->last_obj' can not be empty";
//if($this->formErrorLang == 'fr')
//$msg = "Le champ '$this->last_obj' ne peut être vide";
// $this->objErrorMsg[$this->last_obj][] = $msg;
$this->custom_msg =
''; # remove custom error message
* this method allows to ckeck that the value is a number,
* if parameter floatnumber is true, Digit will accept a float number.
* @param boolean $float_accepted
public function onlyDigit($obj =
'', $float_accepted =
0)
if(!$this->rules($obj))return;
// $res = ereg('^[+-]?[0-9]*\.?[0-9]+$', $_POST[$this->last_obj]);
if(!empty($_POST[$this->last_obj]) &&
!$res)
//if($this->formErrorLang == 'fr')
// $msg = "Le champ '$this->last_obj' ne peut contenir que des chiffres";
// $msg = "Field '$this->last_obj' can only countain digit";
$this->custom_msg =
''; # remove custom error message
* This method allows you to verify $_POST value is equal
public function equal($obj =
'', $value)
* This method allows you to verify $_POST value is equal
public function isEqual($obj =
'', $value)
if(!$this->rules($obj))return;
//if($this->formErrorLang == 'fr')
// $msg = "Le champ '$this->last_obj' doit être égale à '$value'";
// $msg = "Field '$this->last_obj' must be equal at '$value'";
$msg =
$this->getMessage(3, array($obj_name, $value));
* This method allows to verify $_POST value is in the list
public function inList($obj =
'', $value)
$this->inList($obj =
'', $value);
* This method allows to verify $_POST value is in the list
* @param array $arr_value
* @param boolean $case_sensitive
public function isInList($obj =
'', $arr_value, $case_sensitive =
false)
if(!$this->rules($obj))return;
$arr_value_o =
$arr_value;
$arr_value =
array_map('strtolower', $arr_value);
$values =
join(', ', $arr_value_o);
//if($this->formErrorLang == 'fr')
// $msg = "Le champ '$this->last_obj' doit être dans la liste à '$values'";
// $msg = "Field '$this->last_obj' must be in the list '$values'";
$msg =
$this->getMessage(4, array($obj_name, $values));
* this method allows to check if the value contained is only letters characters.
if(!$this->rules($obj))return;
//if($this->formErrorLang == 'fr')
// $msg = "Le champ '$this->last_obj' ne peut contenir que des lettres";
// $msg = "Field '$this->last_obj' can only countain letters";
* this method allows to check if the value given to the object is an email.
public function email($obj =
'')
if(!$this->rules($obj))return;
//if(!eregi("^[_\.0-9a-z-]+@([0-9a-z-]+\.)+[a-z]{2,4}$", $_POST[$this->last_obj]) && (!empty($_POST[$this->last_obj])))
if(!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/i", $_POST[$this->last_obj]) &&
(!empty($_POST[$this->last_obj])))
//if($this->formErrorLang == 'fr')
// $msg = "Le champ '$this->last_obj' n'est pas une adresse mail valide";
// $msg = "Field '$this->last_obj' is not a valid mail address";
* this method allows to check that the value is N length.
if(!$this->rules($obj))return;
//if($this->formErrorLang == 'fr')
// $msg = "Le champ '$this->last_obj' doit contenir '$length' caractères";
// $msg = "Field '$this->last_obj' must contain '$length' characters";
$msg =
$this->getMessage(7, array($obj_name,$length));
* method allows you to put lenght minimum for a chain of character.
public function minLength($obj =
'', $length)
if(!$this->rules($obj))return;
//if($this->formErrorLang == 'fr')
// $msg = "Le champ '$this->last_obj' doit contenir au moins '$length' caractères";
// $msg = "Field '$this->last_obj' must contain at least '$length' characters";
$msg =
$this->getMessage(8, array($obj_name,$length));
* this method allows you to check that the object does not exceed the N lenght.
public function maxLength($obj =
'', $length)
if(!$this->rules($obj))return;
//if($this->formErrorLang == 'fr')
// $msg = "Le champ '$this->last_obj' doit contenir au maximum '$length' caractères";
// $msg = "Field '$this->last_obj' must contain '$length' characters maximum";
$msg =
$this->getMessage(9, array($obj_name, $length));
* method allows to check if the object datas converted as parameters correspond to the pattern converted as parameter.
* The last argument(facultative) corresponds to the message in the event of error.
if(!$this->rules($obj))return;
// if(is_array($_POST[$this->last_obj]) || (!empty($_POST[$this->last_obj]) && !eregi($pattern, $_POST[$this->last_obj])))
* This method allows to control if object countains only alphabetic caracters
public function alpha($obj, $except =
'')
// verify if the obj is on parameter, per defect or is missed
if(!$this->rules($obj)) return;
//if($this->formErrorLang == 'fr')
// $mess = "Le champ '$this->last_obj' contient des caractères non alphabétique";
// $mess = "Field '$this->last_obj' countains non alphabetic characters";
$pattern =
'[[:alpha:]]';
$pattern =
'('.
$pattern.
'|'.
$tmp_pattern.
')';
* This method allows to control if object countains only alphanumeric characters
// verify if the obj is on parameter, per defect or is missed
if(!$this->rules($obj)) return;
//if($this->formErrorLang == 'fr')
// $mess = "Le champ '$this->last_obj' contient des caractères non alphanumérique";
// $mess = "Field '$this->last_obj' countains non alphanumeric characters";
$pattern =
'[[:alnum:]]';
$pattern =
'('.
$pattern.
'|'.
$tmp_pattern.
')';
* this method allows to verify a html form object is well filled. Format parameter must be a string composed by :
* d -> day m -> month y -> year 2 digits Y -> year 4 digits H -> hour i -> minutes s -> seconds
public function date($obj, $format)
* This method allows to verify a html form object is well filled. Format parameter must be a string composed by :
* d -> day m -> month y -> year 2 digits Y -> year 4 digits H -> hour i -> minutes
public function isDate($obj, $format)
// verify if the obj is on parameter, per defect or is missed
if(!$this->rules($obj)) return;
//if($this->formErrorLang == 'fr')
// $mess = "Le champ '$this->last_obj' n'est pas une date valide , format autorisé $format";
// $mess = "Field '$this->last_obj' is not a valid date, format allowed $format";
$mess =
$this->getMessage(11,array($obj_name,$format));
* This method allows to control the value of your form is a correct url.
public function url($obj, $format =
'http://|https://|ftp://')
// verify if the obj is on parameter, per defect or is missed
if(!$this->rules($obj)) return;
$pattern =
"^($format2){0,1}[A-Za-z0-9][A-Za-z0-9\-\.]+[A-Za-z0-9]\.[A-Za-z]{2,}[\43-\176]*$";
//if($this->formErrorLang == 'fr')
// $mess = "Le champ '$this->last_obj' n'est pas une url valide";
// $mess = "Field '$this->last_obj' is not a valid url";
* method allows you to control the presence, the size and/or the extention of a file when it will be upload.
* Now, you can specify the size by adding Ko or Mo
* @param boolean $required
public function fileControl($obj, $required =
'', $size =
'', $mimes =
'', $ext =
'')
// check if the obj is on parameter, per defect or is missed
if(!$this->rules($obj)) return;
// check if the type of controled obj is upload type
// error arguments are missing
//if($this->formErrorLang == 'fr')
// die("<b>Erreur</b> : La restriction <b>fileControl</b> ne peut pas contrôler l'objet <b>$obj</b> <br> ou alors l'objet <b>$obj</b> n'existe pas");
// die("<b>Error</b> : The restriction <b>fileControl</b> cannot control the object <b>$obj</b> or then the <b>$obj</b> object does not exist");
//die($this->getMessage(13, array($obj_name)));
//if($this->formErrorLang == 'fr')
// $msg = "Le champ '$this->last_obj' doit être rempli";
// $msg = "Field '$this->last_obj' cannot be empty";
// Control of the maximum file length
if(!empty($size) &&
!is_int($size))
if(!empty($size) &&
($_FILES[$this->last_obj]['size'] >
$size))
//if($this->formErrorLang == 'fr')
// $msg = "$this->last_obj: La taille du fichier {$_FILES[$this->last_obj]['name']} dépasse la taille maximum autorisée qui est de $taille_origin";
// $msg = "$this->last_obj: he {$_FILES[$this->last_obj]['name']} 's file size is over than the allowed's maximum size which is $taille_origin";
$msg =
$this->getMessage(26, array($obj_name, $taille_origin));
$ext_arr =
array_map('strtolower', $ext_arr);
// take the extension of the file
//@ereg("\.([^\.]*$)", $_FILES[$this->last_obj]['name'], $elts);
//if($this->formErrorLang == 'fr')
// $msg = "$this->last_obj: L'extension du fichier {$_FILES[$this->last_obj]['name']} n'est pas autorisée, seulement '$ext'";
// $msg = "$this->last_obj: The extension of file {$_FILES[$this->last_obj]['name']} is not allowed, only '$ext'";
$msg =
$this->getMessage(14, array($obj_name, $ext));
// Control MIME of file type
$mimes_arr =
array_map('strtolower', $mimes_arr);
//if($this->formErrorLang == 'fr')
// $msg = "$this->last_obj: Le type MIME `{$_FILES[$this->last_obj]['type']}` de votre fichier {$_FILES[$this->last_obj]['name']} n'est pas autorisé, seulement '$mimes'";
// $msg = "$this->last_obj: The MIME type `{$_FILES[$this->last_obj]['type']}` of {$_FILES[$this->last_obj]['name']} is not allowed, only '$mimes'";
* this method allows to modify the language in which the error messages will be posted.
* method allows you to turn an object as error.
public function addError($obj =
'', $message =
'')
if(!$this->rules($obj))return;
if(TPLN_OUTPUT_CHARSET ==
'utf-8')
* method allows you to control the picture width and height uploaded.
* The object name can be forgotten if it has been used in a other method previously.
// check if the obj is on parameter, per defect or is missed
if(!$this->rules($obj)) return;
// check if there is exists one restriction at least
if((empty($w)) &&
(empty($h)))
// error the arguments are missing
//if($this->formErrorLang == 'fr')
// die("Argument manquant sur la methode imgStrictDimension contrôlant l'objet $this->last_obj ");
// die("Argument missing on the method imgStrictDimension controlling the $this->last_obj object");
//die($this->getMessage(16, array($obj_name)));
else // at least onr argument exists
// check if the type of controled obj is upload type
// Erreur the obj is not correct
//if($this->formErrorLang == 'fr')
// die("Erreur : La restriction imgStrictDimension peut pas contrôler l'objet $this->last_obj ou alors l'objet $this->last_obj n'existe pas");
// die("Error : The restriction imgStrictDimension cannot control the object $this->last_obj or then the $this->last_obj object does not exist");
//die($this->getMessage(17,array($obj_name,$obj_name)));
// if we upload the picture and if the picture exixts
// eregi('^image/', $_FILES[$this->last_obj]['type'])
) &&
# ,the type is picture
if(!empty($w) &&
($w !=
$dimension[0]))
if(!$this->errorCustom()) # if the error has already referenced
if(($dimension[0] -
$w) >
0) # calculate the diff�rences
//$msg = "La largeur de l'image {$_FILES[$this->last_obj]['name']} est trop $relation de " . abs($dimension[0] - $w) . " pixels (autorisé $w px)";
$msg =
$this->getMessage(27,array($obj_name, $relation, abs($dimension[0] -
$w), $w));
if(($dimension[0] -
$w) >
0)
//$msg = "The width of the image {$_FILES[$this->last_obj]['name']} is too $relation by " . abs($dimension[0] - $w) . " pixels (allowed $w px)";
$msg =
$this->getMessage(27,array($obj_name, $relation, abs($dimension[0] -
$w), $w));
if(!empty($h) &&
($h !=
$dimension[1]))
if(($dimension[1] -
$h) >
0)
//$msg = "La hauteur de l'image {$_FILES[$this->last_obj]['name']} est trop $relation de " . abs($dimension[1] - $h) . " pixels (autorisé $h px)";
$msg =
$this->getMessage(28,array($obj_name, $relation, abs($dimension[1] -
$h),$h));
if(($dimension[1] -
$h) >
0)
//$msg = "The height of the image {$_FILES[$this->last_obj]['name']} is too $relation by " . abs($dimension[1] - $h) . " pixels (allowed $h px)";
$msg =
$this->getMessage(28,array($obj_name, $relation, abs($dimension[1] -
$h),$h));
* This method allows to control the width of uploaded image.
* The list of supported operator is : - '<' - '<=' - '=' - '>' - '>='
* @param string $operator
// check if the obj is on parameter, per defect or is missed
if(!$this->rules($obj)) return;
// check if there is exists one restriction at least
if(!in_array($operator, array('<', '<=', '=', '>', '>=')))
// error the arguments are missing
//if($this->formErrorLang == 'fr')
// die("Operateur non valide sur la methode imgControlWidth controlant l'objet $this->last_obj ");
// die("Operator not valid on method imgControlWidth controling the $this->last_obj object");
//die($this->getMessage(18,array($obj_name)));
//if($this->formErrorLang == 'fr')
// die("Largeur non valide sur la methode imgControlWidth contrôlant l'objet $this->last_obj ");
// die("Width not valid on method imgControlWidth controling the $this->last_obj object");
//die($this->getMessage(19,array($obj_name)));
// check if the type of controled obj is upload type
// error the ojbect is not correct
//if($this->formErrorLang == 'fr')
// die("Erreur : La restriction imgControlWidth peut pas contrôler l'objet $this->last_obj ou alors l'objet $this->last_obj n'existe pas");
// die("Error : The restriction imgControlWidth can not control the object $this->last_obj or then the $this->last_obj object does not exist");
//die($this->getMessage(20,array($obj_name, $obj_name)));
// if we upload a picture and if the picture exixts
if(($_FILES) &&
# if we upload
// eregi('^image/', $_FILES[$this->last_obj]['type'])
) &&
# the type is picture
if($operator ==
'<' &&
$dimension[0] <
$width)$res =
true;
elseif($operator ==
'<=' &&
$dimension[0] <=
$width)$res =
true;
elseif($operator ==
'=' &&
$dimension[0] =
$width)$res =
true;
elseif($operator ==
'>' &&
$dimension[0] >
$width)$res =
true;
elseif($operator ==
'>=' &&
$dimension[0] >=
$width)$res =
true;
if(!$this->errorCustom()) # if the error has already referenced
//if($this->formErrorLang == 'fr') # we select the language
// $msg = "La largeur de l'image {$_FILES[$this->last_obj]['name']} doit être $operator à $width pixels";
// $msg = "The width of the image {$_FILES[$this->last_obj]['name']} must be $operator at $width pixels";
$msg =
$this->getMessage(21, array($obj_name, $operator, $width));
* This method allows you to control the height of uploaded image.
* The list of supported operator is : - '<' - '<=' - '=' - '>' - '>='
* @param string $operator
// check if the obj is on parameter, per defect or is missed
if(!$this->rules($obj)) return;
// check if there is exists one restriction at least
if(!in_array($operator, array('<', '<=', '=', '>', '>=')))
// error the arguments are missing
//if($this->formErrorLang == 'fr')
// die("Operateur non valide sur la methode imgControlHeight contrôlant l'objet $this->last_obj ");
// die("Operator not valid on method imgControlHeight controling the $this->last_obj object");
//die($this->getMessage(18, array($obj_name)));
//if($this->formErrorLang == 'fr')
// die("Hauteur non valide sur la methode imgControlHeight contrôlant l'objet $this->last_obj ");
// die("Height not valid on method imgControlHeight controling the $this->last_obj object");
//die($this->getMessage(22, array($obj_name)));
// check if the type of controled obj is upload type
// error the ojbect is not correct
//if($this->formErrorLang == 'fr')
// die("Erreur : La restriction imgControlHeight ne peut pas contrôler l'objet $this->last_obj ou alors l'objet $this->last_obj n'existe pas");
// die("Error : The restriction imgControlHeight can not control the object $this->last_obj or then the $this->last_obj object does not exist");
//die($this->getMessage(20, array($obj_name, $this->last_obj)));
// if we upload a picture and if the picture exixts
if(($_FILES) &&
# if we upload
// eregi('^image/', $_FILES[$this->last_obj]['type'])
) &&
# ,the type is picture
if($operator ==
'<' &&
$dimension[1] <
$width)$res =
true;
elseif($operator ==
'<=' &&
$dimension[1] <=
$width)$res =
true;
elseif($operator ==
'=' &&
$dimension[1] =
$width)$res =
true;
elseif($operator ==
'>' &&
$dimension[1] >
$width)$res =
true;
elseif($operator ==
'>=' &&
$dimension[1] >=
$width)$res =
true;
if(!$this->errorCustom()) # if the error has already referenced
//if($this->formErrorLang == 'fr') # we select the language
// $msg = "La Hauteur de l'image {$_FILES[$this->last_obj]['name']} doit être $operator à $width pixels";
// $msg = "The Height of the image {$_FILES[$this->last_obj]['name']} must be $operator at $width pixels";
$msg =
$this->getMessage(23, array($obj_name, $operator, $width));
* treatment of the formulaire directly in PHP
* @param string $elements
public function formParse($elements, $source)
//$errs = array_keys($this->objErrorMsg);
// capture the relevant formulaire
$motif =
"<form [^>]* [^>]*>(.*)<\/form>";
$motif =
"<form [^>]* name=\"$this->formName\"[^>]*>(.*)<\/form>";
$inputs['__ALL'] =
array();
$inputs['__ALL'] =
$arr[0];
$_inputs =
array(); // contains the name of inputs
for($i =
0; $i <
count($inputs['__ALL']); $i++
)
$name =
$this->extractStr($inputs['__ALL'][$i], 'name="', '"');
$type =
$this->extractStr($inputs['__ALL'][$i], 'type="', '"');
if(strpos($inputs['__ALL'][$i], 'value="') !==
false)
$value =
$this->extractStr($inputs['__ALL'][$i], 'value="', '"');
if(strpos($inputs['__ALL'][$i], 'style="') !==
false)
$style =
$this->extractStr($inputs['__ALL'][$i], 'style="', '"');
if($inputs['__ALL'][$i][strlen($inputs['__ALL'][$i])-
2] ==
'/')$xhtml =
true;
if(!in_array($name, $_inputs))$_inputs[] =
$name;
$a =
array('type' =>
$type, 'value_set' =>
$value_set, 'value' =>
$value, 'style_set' =>
$style_set, 'style' =>
$style, 'xhtml' =>
$xhtml, 'html' =>
$inputs['__ALL'][$i]);
// $selects['__ALL'] = array();
//$motif = "<select[^>]*>(.*)<\/select>";
//if(preg_match_all("/$motif/mis", $form_html, $arr))
//$selects['__ALL'] = $arr[0];
$selects['__ALL'] =
array();
$arri =
$this->extractStr($tmpi, '<select', '</select>', true);
if(!empty($arri))$selects['__ALL'][] =
$arri;
$_selects =
array(); // contains the name of selects
for($i =
0; $i <
count($selects['__ALL']); $i++
)
$name =
$this->extractStr($selects['__ALL'][$i], 'name="', '"');
if(strpos($selects['__ALL'][$i], 'style="') !==
false)
$style =
$this->extractStr($selects['__ALL'][$i], 'style="', '"');
// take the style of options and values
//$motif = "<option[^>]*>(.*)<\/option>";
//if(preg_match_all("/$motif/im", $selects['__ALL'][$i], $arr))
//$options['__ALL'] = $arr[0];
$options['__ALL'] =
array();
$tmpi =
$selects['__ALL'][$i];
$arri =
$this->extractStr($tmpi, '<option', '</option>', true);
if(!empty($arri))$options['__ALL'][] =
$arri;
for($j =
0; $j <
count($options['__ALL']); $j++
)
$value_op =
$this->extractStr($options['__ALL'][$j], 'value="', '"');
if(strpos($options['__ALL'][$j], 'style="') !==
false)
$style_op =
$this->extractStr($options['__ALL'][$j], 'style="', '"');
$option[] =
array('value' =>
$value_op, 'style_set' =>
$style_op_set, 'style' =>
$style_op, 'html' =>
$options['__ALL'][$j], 'parsed' =>
$options['__ALL'][$j]);
if(!in_array($name, $_selects))$_selects[] =
$name;
$select[$name][] =
array('style' =>
$style, 'style_set' =>
$style_set, 'option' =>
$option, 'html' =>
$selects['__ALL'][$i]);
$textareas['__ALL'] =
array();
//$motif = "<textarea[^>]*>(.*)<\/textarea>";
//if(preg_match_all("/$motif/i", $form_html, $arr))
//$textareas['__ALL'] = $arr[0];
$arri =
$this->extractStr($tmpi, '<textarea', '</textarea>', true);
if(!empty($arri))$textareas['__ALL'][] =
$arri;
$_textareas =
array(); // contains name of selects
for($i =
0; $i <
count($textareas['__ALL']); $i++
)
$name =
$this->extractStr($textareas['__ALL'][$i], 'name="', '"');
if(strpos($textareas['__ALL'][$i], 'style="') !==
false)
$style =
$this->extractStr($textareas['__ALL'][$i], 'style="', '"');
$value =
$this->extractStr($textareas['__ALL'][$i], '>', '</textarea>');
if(!in_array($name, $_textareas))$_textareas[] =
$name;
$textarea[$name][] =
array('value' =>
$value, 'style_set' =>
$style_set, 'style' =>
$style, 'html' =>
$textareas['__ALL'][$i]);
// assign our values ***************************************************************************
$form_parsed =
$form_init;
foreach($elements as $key =>
$val)
$multiple_values =
false;
if(in_array($input[$name][0]['type'], array('text', 'hidden', 'password', 'file')))
$t =
$input[$name][0]['html'];
// value existante or not ?
if(!$input[$name][0]['value_set'])
if($input[$name][0]['xhtml'])
$t =
str_replace('/>', ' value="' .
$val .
'" />', $t);
$t =
str_replace('value="' .
$input[$name][0]['value'] .
'"', ' value="' .
$val .
'"', $t);
// input text error? ****************************************************************************
if(in_array($name, $errs) &&
($input[$name][0]['type'] ==
'text' ||
$input[$name][0]['type'] ==
'password' ||
$input[$name][0]['type'] ==
'file'))
$t2 =
'<span style="color:'.
$this->formErrorColor.
'; font-weight:bold;">';
$style =
trim($input[$name][0]['style']);
if(!empty($style) &&
$style[strlen($style)-
1] !=
';')$style .=
'; ';
if(!$input[$name][0]['style_set'])
if($input[$name][0]['xhtml'])
$t =
str_replace(' />', ' style="' .
$border_color .
'" />', $t);
$t =
str_replace('>', ' style="' .
$border_color .
'" >', $t);
if($input[$name][0]['xhtml'])
$t =
str_replace(' style="' .
$input[$name][0]['style'] .
'"', ' style="' .
$style .
$border_color .
'"', $t);
$t =
str_replace(' style="' .
$input[$name][0]['style'] .
'"', ' style="' .
$style .
$border_color .
'"', $t);
// *******************************************************************************************
$form_parsed =
str_replace($input[$name][0]['html'], $t, $form_parsed);
elseif($input[$name][0]['type'] ==
'radio')
// group of radios have the same name
for($i =
0; $i <
count($input[$name]); $i++
)
$t =
$input[$name][$i]['html'];
if($input[$name][$i]['value'] ==
$val)
if(strpos($input[$name][$i]['html'], ' checked') ===
false)
if($input[$name][$i]['xhtml'])
else // take off the checked
// radio error? ****************************************************************************
$t2 =
'<span style="color:'.
$this->formErrorColor.
'; font-weight:bold;">';
$style =
trim($input[$name][$i]['style']);
if(!empty($style) &&
$style[strlen($style)-
1] !=
';')$style .=
'; ';
if(!$input[$name][$i]['style_set'])
if($input[$name][$i]['xhtml'])
$t =
str_replace(' />', ' style="' .
$border_color .
'" />', $t);
$t =
str_replace('>', ' style="' .
$border_color .
'" />', $t);
if($input[$name][$i]['xhtml'])
$t =
str_replace(' style="' .
$input[$name][$i]['style'] .
'"', ' style="' .
$style .
$border_color .
'"', $t);
$t =
str_replace(' style="' .
$input[$name][$i]['style'] .
'"', ' style="' .
$style .
$border_color .
'"', $t);
// *******************************************************************************************
$form_parsed =
$this->str_replace_count($input[$name][$i]['html'], $t, $form_parsed, 1);
elseif($input[$name][0]['type'] ==
'checkbox')
for($j =
0; $j <
count($elements[$name_init]); $j++
)
$values[] =
$elements[$name_init][$j];
// group of checkboxs which have the same name
for($i =
0; $i <
count($input[$name]); $i++
)
$t =
$input[$name][$i]['html'];
if((!$multiple_values &&
$input[$name][$i]['value'] ==
$val) ||
($multiple_values &&
in_array($input[$name][$i]['value'], $values)))
if(strpos($input[$name][$i]['html'], ' checked') ===
false)
if($input[$name][$i]['xhtml'])
else // take off the checked
// checkbox error ? ****************************************************************************
$t2 =
'<span style="color:'.
$this->formErrorColor.
'; font-weight:bold;">';
$style =
trim($input[$name][$i]['style']);
if(!empty($style) &&
$style[strlen($style)-
1] !=
';')$style .=
'; ';
if(!$input[$name][$i]['style_set'])
if($input[$name][$i]['xhtml'])
$t =
str_replace(' />', ' style="' .
$border_color .
'" />', $t);
$t =
str_replace('>', ' style="' .
$border_color .
'" >', $t);
if($input[$name][$i]['xhtml'])
$t =
str_replace(' style="' .
$input[$name][$i]['style'] .
'"', ' style="' .
$style .
$border_color .
'"', $t);
$t =
str_replace(' style="' .
$input[$name][$i]['style'] .
'"', ' style="' .
$style .
$border_color .
'"', $t);
// *******************************************************************************************
$form_parsed =
$this->str_replace_count($input[$name][$i]['html'], $t, $form_parsed, 1);
$t =
$textarea[$name][0]['html'];
$t =
str_replace('>' .
$textarea[$name][0]['value'] .
'</textarea>', '>' .
$val .
'</textarea>', $t);
// textarea error ? ****************************************************************************
$style =
trim($textarea[$name][0]['style']);
if(!empty($style) &&
$style[strlen($style)-
1] !=
';')$style .=
'; ';
if(!$textarea[$name][0]['style_set'])
$t =
$this->str_replace_count('>', ' style="' .
$border_color .
'" >', $t, 1);
$t =
$this->str_replace_count(' style="' .
$textarea[$name][0]['style'] .
'"', ' style="' .
$style .
$border_color .
'"', $t, 1);
$t2 =
'<span style="color:'.
$this->formErrorColor.
'; font-weight:bold;">';
// *******************************************************************************************
$form_parsed =
str_replace($textarea[$name][0]['html'], $t, $form_parsed);
// simple select && multiple
for($i =
0; $i <
count($select[$name]); $i++
)
for($j =
0; $j <
count($elements[$name_init]); $j++
)
$values[] =
$elements[$name_init][$j];
for($j =
0; $j <
count($select[$name][$i]['option']); $j++
)
if((!$multiple_values &&
$select[$name][$i]['option'][$j]['value'] ==
$val) ||
($multiple_values &&
in_array($select[$name][$i]['option'][$j]['value'], $values)))
if(strpos($select[$name][$i]['option'][$j]['html'], ' selected') ===
false)
$select[$name][$i]['option'][$j]['parsed'] =
$this->str_replace_count('>', ' selected>', $select[$name][$i]['option'][$j]['html'], 1);
else // remove the selected
$select[$name][$i]['option'][$j]['parsed'] =
$this->str_replace_count(' selected', ' ', $select[$name][$i]['option'][$j]['html'], 1);
// replace the correct select
$t =
$select[$name][$i]['html'];
for($j =
0; $j <
count($select[$name][$i]['option']); $j++
)
$t =
$this->str_replace_count($select[$name][$i]['option'][$j]['html'], $select[$name][$i]['option'][$j]['parsed'], $t, 1);
// select error ? ****************************************************************************
$style =
trim($select[$name][$i]['style']);
if(!empty($style) &&
$style[strlen($style)-
1] !=
';')$style .=
'; ';
if(!$select[$name][$i]['style_set'])
$t =
$this->str_replace_count('>', ' style="' .
$bg_color .
'" >', $t, 1);
$t =
$this->str_replace_count(' style="' .
$select[$name][$i]['style'] .
'"', ' style="' .
$style .
$bg_color .
'"', $t, 1);
$t2 =
'<span style="color:'.
$this->formErrorColor.
'; font-weight:bold;">';
// *******************************************************************************************
$form_parsed =
str_replace($select[$name][$i]['html'], $t, $form_parsed);
* This method allows to get total errors, it must be palced before the method formIsValid()
* No protection for these values
* Default charset for input protection
* protect data agains user attacks
* @param bool $x_html_entities
* @param bool $x_protect_vars
public function formXEntities($arr, $x_html_entities=
true, $x_protect_vars=
true)
foreach($arr as $key =>
$val)
$clean_arr[$key] =
$this->formXEntities($arr[$key], $x_html_entities, $x_protect_vars);
$val =
str_replace(array('{ ', ' }'), array('{', '}'), $val); # clean
$val =
str_replace(array('{', '}'), array('{ ', ' }'), $val);
* method allows to post the all prospective errors. The parameter is a boolean which allows to generate javascript.
* The javascript will allow to keep the data in the form during a post.
public function formIsValid() // destroy the error bolck if it has not a post
// capture the relevant formulaire
$motif =
"<form [^>]* [^>]*>(.*)<\/form>";
$motif =
"<form [^>]* name=\"$this->formName\"[^>]*>(.*)<\/form>";
preg_match("/$motif/ims", $this->f[$this->f_no]['buffer'], $arr);
// if the block form contains form_error
$form_error_inside =
false;
if(strpos($form_html, '<bloc::form_error>') !==
false)
$form_error_inside =
true;
$form_parsed =
$this->formParse($this->row_val, $this->f[$this->f_no]['buffer']);
$this->f[$this->f_no]['buffer'] =
str_replace($form_html, $form_parsed, $this->f[$this->f_no]['buffer']);
// if($form_error_inside && $this->blocExists('form_error'))
if($this->blocExists('form_error'))
$this->EraseBloc('form_error');
if($this->blocExists('form_valid'))
$this->EraseBloc('form_valid');
$form_parsed =
$this->formParse($_POST, $this->f[$this->f_no]['buffer']);
$this->f[$this->f_no]['buffer'] =
str_replace($form_html, $form_parsed, $this->f[$this->f_no]['buffer']);
if($this->blocExists('form_valid'))
$this->EraseBloc('form_valid');
// html coding errors messages
// $this->msg_err = array_unique($this->msg_err);
foreach($this->msg_err as $key =>
$val)
$this->Parse('form_error.msg', $m);
$this->Loop('form_error');
if($this->blocExists('form_error'))
$this->EraseBloc('form_error');
$form_error_inside_form =
false;
if($this->blocExists('form_valid'))
$f_v =
$this->getBlocInFile('form_valid');
// if the block form:error is in the form
if(strpos($form_html, '<bloc::form_error>') !==
false)$form_error_inside_form =
true;
// replace directly in the buffer
$this->f[$this->f_no]['buffer'] =
str_replace($form_html, $f_v, $this->f[$this->f_no]['buffer']);
// the block form_error is outside, it is automatically remplaced
if(!$form_error_inside_form &&
$this->blocExists('form_error'))
$this->EraseBloc('form_error');
if($this->blocExists('form_valid'))
$this->EraseBloc('form_valid');
// delete the values of captcha
* This method allows to add a captcha verification useful to fight against spam attacks
// generate the number id
$str =
'<img src="'.
TPLN_WEB_PATH.
'/plugin/form/captcha.php'.
$sn.
'" alt="Security code" style="border:0px;" /><br />'.
"\n";
$str .=
'<input id="tpln_captcha" name="tpln_captcha" type="text" maxlength="5" />';
if(!isset
($_SESSION))return;
if($sn ==
'PHPSESSID')$sn =
'';
unset
($_SESSION['tpln_captcha']);
unset
($_SESSION['tpln_captcha_nb']);
unset
($_SESSION[$sn]['tpln_captcha']);
unset
($_SESSION[$sn]['tpln_captcha_nb']);
* This method allows to define a number of error for the user, by default 0: illimited
if($sn ==
'PHPSESSID')$sn =
'';
if(!isset
($_SESSION['tpln_captcha_nb']))
$_SESSION['tpln_captcha_nb'] =
0;
$_SESSION['tpln_captcha_nb']++
;
unset
($_SESSION['tpln_captcha']);
unset
($_SESSION['tpln_captcha_nb']);
//die('Error: You can not publish more than '.$this->captcha_max.' times');
//die($this->getMessage(24,array($this->captcha_max)));
if(!isset
($_SESSION[$sn]['tpln_captcha_nb']))
$_SESSION[$sn]['tpln_captcha_nb'] =
0;
$_SESSION[$sn]['tpln_captcha_nb']++
;
if($_SESSION[$sn]['tpln_captcha_nb'] ==
$this->captcha_max)
unset
($_SESSION[$sn]['tpln_captcha']);
unset
($_SESSION[$sn]['tpln_captcha_nb']);
//die('Error: You can not publish more than '.$this->captcha_max.' times');
//die($this->getMessage(24,array($this->captcha_max)));
* this method verifies automatically captcha
// verify if the obj is on parameter, per defect or missed
if(!$this->rules($obj)) return;
if($sn ==
'PHPSESSID')$sn =
'';
$session_tpln_captcha =
$_SESSION['tpln_captcha'];
$session_tpln_captcha =
$_SESSION[$sn]['tpln_captcha'];
if(strcmp($session_tpln_captcha, $_POST['tpln_captcha']) !=
0)
//if($this->formErrorLang == 'fr')
// $msg = "Le code de sécurité n'est pas valide";
// $msg = "Your security code is not valid";
$_POST['tpln_captcha'] =
''; // delete the field
Documentation generated on Sat, 06 Mar 2010 21:33:57 +0100 by phpDocumentor 1.4.3