Salut à toutes et à tous !
J'ai un petit problème , qui m'en pose de gros x) je m'explique :
J'ai une fonction qui est censée m'afficher des erreurs , mais elle ne me les affichent pas j'ai essayer tout et n'importe quoi j'y arrive pas , je sais je ne suis pas très clair dans mes explications :/
Voilà le helper :
<?php
class Form{
private $data;
private $errors;
public function setErrors($errors){
$this->errors = $errors;
}
function getErrors($field){
if(isset($this->errors$field])):
return '<span class="error">'.$this->errors$field].'</span>';
endif;
}
function set($data){
$this->data = $data;
}
public function input($field,$label = NULL,$attributes = array()){
$r = '';
if($label != NULL):
$r = '<label for="'.$field.'">'.$label.'</label>';
endif;
$r .= '<input type="text" name="data'.$field.']" id="'.$field.'"';
if(isset($this->data$field])):
$r .= ' value="'.$this->data$field].'"';
endif;
foreach($attributes as $k=>$v){
$r .= $k.'="'.$v.'"';
}
$r .= '/>';
$r .= $this->getErrors($field);
return $r;
}
public function email($field,$label = NULL,$attributes = array()){
$r = '';
if($label != NULL):
$r = '<label for="'.$field.'">'.$label.'</label>';
endif;
$r .= '<input type="email" name="data'.$field.']" id="'.$field.'"';
if(isset($this->data$field])):
$r .= ' value="'.$this->data$field].'"';
endif;
foreach($attributes as $k=>$v){
$r .= $k.'="'.$v.'"';
}
$r .= '/>';
$r .= $this->getErrors($field);
return $r;
}
public function hidden($field,$attributes = array()){
$r = '<input type="hidden" name="data'.$field.'"';
foreach($attributes as $k=>$v){
$r .= $k.'="'.$v.'"';
}
$r .= '/>';
return $r;
}
public function file($field,$label,$attributes = array()){
$r = '';
if($label != NULL):
$r = '<label for="'.$field.'">'.$label.'</label>';
endif;
$r .= '<input type="file" name="data'.$field.'"';
foreach($attributes as $k=>$v){
$r .= $k.'="'.$v.'"';
}
$r .= '/>';
$r .= $this->getErrors($field);
return $r;
}
public function submit($field,$value,$attributes = array()){
$r = '<input type="SUBMIT" name="'.$field.'" value="'.$value.'"';
foreach ($attributes as $k=>$v){
$r .= $k.'="'.$v.'"';
}
$r .= '/>';
return $r;
}
public function password($field,$label = NULL,$attributes = array()){
$r = '';
if($label != NULL):
$r = '<label for="'.$field.'">'.$label.'</label>';
endif;
$r .= '<input type="password" name="data'.$field.']"';
foreach ($attributes as $k=>$v){
$r .= $k.'="'.$v.'"';
}
$r .= '/>';
$r .= $this->getErrors($field);
return $r;
}
public function select($field,$label = NULL,$options){
$r = '';
if($label != NULL):
$r = '<label for="'.$field.'">'.$label.'</label>';
endif;
$r .= '<select name="data'.$field.']">';
foreach ($options as $k=>$v){
if($k == $this->data$field]):
$r .= '<option value"'.$k.'" selected="selected">'.$v.'</option>';
else:
$r .= '<option value"'.$k.'">'.$v.'</option>';
endif;
}
$r .= '</select>';
$r .= $this->getErrors($field);
return $r;
}
public function radio($field,$label = NULL,$attributes = array()){
$r = '';
if($label != NULL):
$r = '<label for="'.$label.'">'.$label.'</label>';
endif;
$r .= '<input type="radio" name="data'.$field.']" id="'.$label.'"';
if(isset($this->data$field])):
$r .= ' value="'.$this->data$field].'"';
endif;
foreach($attributes as $k=>$v){
$r .= $k.'="'.$v.'"';
}
$r .= '/>';
$r .= $this->getErrors($field);
return $r;
}
public function textarea($field,$label = NULL,$options){
$r = '';
if($label != NULL):
$r = '<label for="'.$field.'">'.$label.'</label>';
endif;
$r .= '<textarea name="data'.$field.']" id="'.$field.'"';
foreach ($options as $k=>$v){
$r .= $k.'="'.$v.'"';
}
$r .= '>';
if(isset($this->data$field])):
$r .= $this->data$field];
endif;
$r .= '</textarea>';
$r .= $this->getErrors($field);
return $r;
}
}
?>
Voilà mon code :
<?php
session_start();
require_once('../_query/_database/bdd.php');
require_once('../_query/_classes/security.class.php');
require_once('../_query/_helper/form.helper.php');
?>
<?php
require '../_query/global.php';
$isLogged = Security::isLogged();
if($isLogged == 1):
$form = new Form();
if(isset($_GET'do']) && isset($_GET'wh']) && $_GET'do'] == "modif" && $_GET'wh'] == "pass" && isset($_POST'data'])):
if($_POST'data']'old_password'] != NULL):
if($_POST'data']'new_password'] != NULL):
if($_POST'data']'new_password_verif'] != NULL):
if(strlen($_POST'data']'new_password'])<60):
if(strlen($_POST'data']'new_password'])>5):
if(sha1($_POST'data']'old_password']) == $_SESSION'Auth']'pass']):
if($_POST'data']'new_password'] == $_POST'data']'new_password_verif']):
$pass = Security::bdd(sha1($_POST'data']'new_password']));
$sql = "UPDATE members SET pass = :pass WHERE pseudo = :pseudo";
$req = $bdd->prepare($sql);
$req->execute(array(
"pass" => $pass,
"pseudo" => $_SESSION'Auth']'pseudo']
));
$_SESSION'Auth']'pass'] = $pass;
header('Location: '.DEFAULT_URL.'account-modif-pass');
else:
echo '1';
$form->setErrors(array("new_password_verif" => "Pass différents"));
endif;
else:
echo '2';
$form->setErrors(array("old_password" => "Mauvais pass"));
endif;
else:
echo '3';
$form->setErrors(array("new_password" => "Pass trop court"));
endif;
else:
echo '4';
$form->setErrors(array("new_password" => "Pass trop long"));
endif;
else:
echo '5';
$form->setErrors(array("new_password_verif" => "Ce champ est vide"));
endif;
else:
echo '6';
$form->setErrors(array("new_password" => "Ce champ est vide"));
endif;
else:
echo '7';
$form->setErrors(array("old_password" => "Ce champ est vide"));
endif;
endif;
if(isset($_GET'do']) && isset($_GET'wh']) && $_GET'do'] == "modif" && $_GET'wh'] == "email" && isset($_POST'data'])):
if($_POST'data']'old_email'] != NULL):
if($_POST'data']'new_email'] != NULL):
if($_POST'data']'new_email_verif'] != NULL):
if($_POST'data']'old_email'] == $_SESSION'Auth']'email']):
if(filter_var($_POST'data']'new_email'],FILTER_VALIDATE_EMAIL)):
if($_POST'data']'new_email'] == $_POST'data']'new_email_verif']):
$email = Security::bdd($_POST'new_email']);
$sql = "UPDATE members SET email = :email WHERE pseudo = :pseudo";
$req = $bdd->prepare($sql);
$req->execute(array(
"email" => $email,
"pseudo" => $_SESSION'Auth']'pseudo']
));
else:
$form->setErrors(array("new_email_verif" => "Email différentes"));
endif;
else:
$form->setErrors(array("new_email" => "Veuillez rentrer une email valide"));
endif;
else:
$form->setErrors(array("old_email" => "Cette email ne correspond pas avec votre ancienne email"));
endif;
else:
$form->setErrors(array("new_email_verif" => "Ce champ est vide"));
endif;
else:
$form->setErrors(array("new_email" => "Ce champ est vide"));
endif;
else:
$form->setErrors(array("old_email" => "Ce champ est vide"));
endif;
endif;
if(isset($_GET'do']) && isset($_GET'wh']) && $_GET'do'] == "modif" && $_GET'wh'] == "perso" && isset($_POST'data'])):
if($_POST'data']'main'] != NULL):
if($_POST'data']'reroll'] != NULL):
if(strlen($_POST'data']'main'])<255):
$sql = "UPDATE members SET main = :main, reroll = :reroll WHERE pseudo = :pseudo";
$req = $bdd->prepare($sql);
$req->execute(array(
"main" => Security::bdd($_POST'data']'main']),
"reroll" => Security::bdd($_POST'data']'reroll']),
"pseudo" => $_SESSION'Auth']'pseudo'],
));
else:
$form->setErrors(array("main" => "Ce champ fait plus de 255 caractères"));
endif;
else:
$form->setErrors(array("reroll" => "Ce champ est vide"));
endif;
else:
$form->setErrors(array("main" => "Ce champ est vide"));
endif;
endif;
if(isset($_GET'do']) && isset($_GET'wh']) && $_GET'do'] == "modif" && $_GET'wh'] == "moi" && isset($_POST'data'])):
endif;
?>
<nav>
<?php require '../_query/_html/nav.php'; ?>
</nav>
<section style="">
<?php
echo "<div id='account'>";
echo "Bonjour , ".$_SESSION'Auth']'pseudo']."<br />";
echo "Email : ".$_SESSION'Auth']'email']."<br />";
echo "Rang : ".$_SESSION'Auth']'rank'];
echo "<fieldset>";
echo "<legend>Mes paramètres</legend>";
if(isset($_GET'do']) && isset($_GET'wh']) && $_GET'do'] == "modif" && $_GET'wh'] == "pass"):
echo "<dd style='height:170px;'>";
echo "<a href='".DEFAULT_URL."account-modif-email'>Modifier mon email</a>";
echo "<form method='POST' action='".DEFAULT_URL."account-modif-pass'>";
echo $form->password('old_password','Votre ancien pass :', array()).'<br />';
echo $form->password('new_password','Votre nouveau pass :', array()).'<br />';
echo $form->password('new_password_verif','Retaper votre nouveau pass :', array()).'<br />';
echo $form->submit('submit','Changer mon pass', array());
echo "</form>";
echo "<a href='".DEFAULT_URL."account'> << Retour</a>";
elseif(isset($_GET'do']) && isset($_GET'wh']) && $_GET'do'] == "modif" && $_GET'wh'] == "email"):
echo "<dd style='height:150px;'>";
echo "<a href='".DEFAULT_URL."account-modif-pass'>Modifier mon mot de passe</a>";
echo "<form method='POST' action='".DEFAULT_URL."account-modif-email'>";
echo $form->email('old_email','Votre ancienne email :', array()).'<br />';
echo $form->email('new_email','Votre nouvelle email :', array()).'<br />';
echo $form->email('new_email_verif','Retaper votre nouvelle email :', array()).'<br />';
echo $form->submit('submit','Changer mon email', array());
echo "</form>";
echo "<a href='".DEFAULT_URL."account'> << Retour</a>";
else:
echo "<dd>";
echo "<a href='".DEFAULT_URL."account-modif-pass'>Modifier mon mot de passe</a><br />";
echo "<a href='".DEFAULT_URL."account-modif-email'>Modifier mon email</a><br />";
endif;
echo "</dd>";
echo "</fieldset>";
echo "<fieldset>";
echo "<legend>Mes infos</legend>";
if($_SESSION'Auth']'rank'] != "Endormi"):
if(isset($_GET'do']) && isset($_GET'wh']) && $_GET'do'] == "modif" && $_GET'wh'] == "perso"):
echo "<dd style='height:190px;'>";
echo "<a href='".DEFAULT_URL."account-modif-moi'>Moi</a><br />";
echo "<a href='".DEFAULT_URL."account-modif-avatar'>Mon avatar</a><br />";
echo "<form method='POST' action='".DEFAULT_URL."account-modif-perso'>";
echo $form->input('main','Votre main :<br />', array()).'<br />';
echo $form->textarea('reroll','Vos reroll(s) :<br />', array()).'<br />';
echo $form->submit('submit','Modifier', array()).'<br />';
echo "</form>";
echo "<a href='".DEFAULT_URL."account'> << Retour</a>";
elseif(isset($_GET'do']) && isset($_GET'wh']) && $_GET'do'] == "modif" && $_GET'wh'] == "moi"):
echo "<dd style='height:150px;'>";
echo "<a href='".DEFAULT_URL."account-modif-avatar'>Mon avatar</a><br />";
echo "<a href='".DEFAULT_URL."account-modif-perso'>Mes personnages</a><br />";
echo "<form method='POST' action='".DEFAULT_URL."account-modif-moi'>";
echo "<select name='jour'>";
$i=1;
while($i<32){
?><option name="jour" value="<?php echo $i; ?>" /><?php echo $i; ?></option><?php
$i++;
}
echo "</select>";
echo "<select name='mois'>";
$j=1;
while($j<13){
?><option name="mois" value="<?php echo $j; ?>" /><?php echo $j; ?></option><?php
$j++;
}
echo "</select>";
echo "<select name='annee'>";
$a=1900;
while($a<2084){
?><option name="annee" value="<?php echo $a; ?>" /><?php echo $a; ?></option><?php
$a++;
}
echo "</select><br />";
echo '<label>Votre sexe :</label><br />';
echo $form->radio('sex','Femme',array('value'=>'femme'));
echo $form->radio('sex','Homme',array('value'=>'homme')).'<br />';
echo $form->submit('submit','Modifier', array()).'<br />';
echo "</form>";
echo "<a href='".DEFAULT_URL."account'> << Retour</a>";
elseif(isset($_GET'do']) && isset($_GET'wh']) && $_GET'do'] == "modif" && $_GET'wh'] == "avatar"):
echo "<dd style='height:150px;'>";
echo "<a href='".DEFAULT_URL."account-modif-moi'>Moi</a><br />";
echo "<a href='".DEFAULT_URL."account-modif-perso'>Mes personnages</a><br />";
echo "<form method='POST' action='".DEFAULT_URL."account-modif-avatar' enctype='multipart/form-data' ><br />";
echo $form->file('avatar','Votre avatar :(Max 64Ko)<br />', array("size" => "65536", "title"=>"format conseillé : jpg"));
$form->hidden('MAX_FILE_SIZE', array('value' => '65536'));
echo '</form><br />';
echo "<a href='".DEFAULT_URL."account'> << Retour</a>";
else:
echo "<dd>";
echo "<a href='".DEFAULT_URL."account-modif-perso'>Mes personnages</a><br />";
echo "<a href='".DEFAULT_URL."account-modif-moi'>Moi</a><br />";
echo "<a href='".DEFAULT_URL."account-modif-avatar'>Mon avatar</a><br />";
endif;
echo "</dd>";
else:
echo "<span class='error'>Vous n'avez pas accès à cette partie en étant Endormi</span>";
endif;
echo "</fieldset>";
echo "</div>";
else:
echo '<span class="error">Vous devez être connecté(e) pour acceder à cette page</span>';
print_r($_SESSION);
endif;
?>
</section>
<?php
require '../_query/_html/foot.html';
?>
La fonction GetErrors du helper est censée aller chercher les erreurs liées au champ , elle est censée retourner quelque chose . Chose qu'elle ne fait pas :(,
Elle ne fonctionne sur aucun formulaire : l. 130 à 135 , l. 140 à 145 , l.161 à 165 .
Merci de votre aide , j'espère que vous pourrez solutionner mon problème , merci