J'espère que je poste ça au bon endroit !
J'ai une portion html qui me permet de choisir ou d'entrer un nom de ville, la partie {default_tags} étant remplacée au chargement de la page par la regex limitant ce que l'utilisateur peut entrer
Code : Tout sélectionner
<div id="ExistingCity">
<label class="#" for="CityName">{City} : </label><br />
<input list="GcCity" type="text" id="City_choice" name="City_choice" size="20" {default_tags}>
<datalist name="GcCity" id="GcCity">
<!-- LOOP GcCities -->
<option value="{city_no}" label="{ExistingCityName}">{ExistingCityName}</option>
<!-- END LOOP GcCities -->
</datalist>
</div>
Code : Tout sélectionner
class forms
{
private $templates = array(
'login' => '^[a-zA-Z0-9_\-]{4,15}$',
'password' => '^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@!_?*-]).[0-9a-zA-Z@!_?*-]{8,20}$',
'email' => '^[0-9a-zA-Z_\-\@\.]{6,50}$',
'number' => '^[0-9]{1,10}$',
'security' => '^[6]{1}[j]{1}[6]{1}$',
'date' => '^[0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]$', // yyyy-mm-dd --- '^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$',
'default' => '[a-zA-Z0-9àáâãäåçèéêëìíîïðòóôõöùúûüýÿ \!\?\.\'\-\(\)\/\°\[\]\#]{1,500}$',
'GC' => '^GC[A-Z0-9]{1,6}$',
'coordinate' => '^[NS]{1}[ ]{1}[0-9]{2}\°[ ]{1}[0-5]{1}[0-9]{1}.[0-9]{3}[ ]{1}[EW]{1}[ ]{1}[0-9]{3}\°[ ]{1}[0-5]{1}[0-9]{1}.[0-9]{3}$');
private $minimum_length = 4;
private $tag_def;
function __construct($sql_cnx = null)
{
$this -> tag_def = array(
'login' => ' title="{login_charac}" pattern="'.$this -> templates['login'].'"',
'password' => ' title="{password_charac}" pattern="'.$this -> templates['password'].'"',
'email' => 'title="{email_charac}" pattern="'.$this -> templates['email'].'"',
'number' => ' pattern="'.$this -> templates['number'].'"',
'security' => 'pattern="'.$this -> templates['security'].'"',
'date' => ' title="{date_charac}" pattern="'.$this -> templates['date'].'"',
'default' => ' pattern="'.$this -> templates['default'].'"',
'GC' => ' pattern="'.$this -> templates['GC'].'"',
'coordinate' => ' pattern="'.$this -> templates['coordinate'].'"');
$this -> Forbidencharacs = array(
'login' => '#'.$this -> templates['login'].'#',
'password' => '#'.$this -> templates['password'].'#',
'email' => '#'.$this -> templates['email'].'#',
'number' => '#'.$this -> templates['number'].'#',
'security' => '#'.$this -> templates['security'].'#',
'date' => '#'.$this -> templates['date'].'#',
'default' => '#'.$this -> templates['default'].'#',
'GC' => '#'.$this -> templates['GC'].'#',
'coordinate' => '#'.$this -> templates['coordinate'].'#');
$this -> mysql_connexion = $sql_cnx;
if(defined("SQL_PREFIX"))
{
$this -> prefix = SQL_PREFIX;
}
}
Dans le code de ma page php, j'appelle une fonction de ma classe permettant de vérifier les limitations :
Code : Tout sélectionner
if (isset($_POST['City_choice']) and $_POST['City_choice'] !== '')
{
$GcCityName = htmlentities($_POST['City_choice'], ENT_QUOTES, "UTF-8");
$error -> add_error($form -> forbiden_characs($page['City'], $GcCityName, 'default'));
}
Voici la fonction de la classe effectuant les vérifications :
Code : Tout sélectionner
function forbiden_characs($field_name, $field_value, $model_replacement = NULL)
{
// Checks if a forbiden character has been used.
static $pattern;
static $model;
if (!is_null($model_replacement))
{
$model = $model_replacement;
}
else
{
$model = substr($field_name,1,-1);
}
switch($model)
{
case 'login':
$pattern = $this -> Forbidencharacs['login'];
break;
case 'password':
$pattern = $this -> Forbidencharacs['password'];
break;
case 'email':
$pattern = $this -> Forbidencharacs['email'];
break;
case 'date':
$pattern = $this -> Forbidencharacs['date'];
break;
case 'GC':
$pattern = $this -> Forbidencharacs['GC'];
break;
default:
$pattern = $this -> Forbidencharacs['default'];
}
if (preg_match($pattern, $field_value) === 0)
{
// forbiden character.
return $field_name.' : {forbiden_charac}.';
}
return 0;
}
Mais là quand j'entre le mot "Meyrié", mot qui devrait être autorisé avec le template "default", le html laisse bien passer, ce qui est normal, mais pas le PHP.
Sauriez vous où je me plante ?
Merci