Problème sur les conditions d'un formulaire

Résolu/Fermé
europe21 Messages postés 63 Date d'inscription mardi 26 décembre 2017 Statut Membre Dernière intervention 4 février 2024 - Modifié le 6 avril 2018 à 16:47
yg_be Messages postés 22773 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 9 mai 2024 - 6 avril 2018 à 20:31
Bonjour a tous,

J'ai un formulaire qui me permet d'ajouter des éléments dans mon portfolio dont une image qui est uploadé.

Lorsque tout les champs sont plein pas de souci cela fonctionne si j'enleve la condition de l'upload(pourtant c'a fonctionne).

Le problème vient lorsque les champs ne sont pas remplis, c'a part dans le catch et bien sur les messages n'apparaissent pas. Je pense m’être gourer dans les conditions mais je ne trouve pas. Je travaille en mvc orienté objet:

voici mon routeur:
elseif ($_GET['action'] == 'portfolioInsertAction'){
     
        
         $ctrlBackend->portfolioInsertAction(($_FILES['image']['name']),$_POST['titre'],$_POST['description'],$_POST['techno'],$_POST['comment'],$_POST['liens']);
      }


mon controlleur:
class BackendController{
  public $titreError = "" ;
  public $descriptionError = "";
  public $technoError = "";
  public $commentError = "";
  public $imageError = "";
  public $liensError = "";
  public $titre = "";
  public $description = "";
  public $techno = "";
  public $comment = "";
  public $image = "";
  public $liens = "";
  public $isSuccess = true;
  public $imagePath      = '';
  public $imageExtension = '';
  public $isUploadSuccess = false;
 
public function portfolioInsertAction($image, $description, $techno, $comment, $titre,$liens)
{
 
     
 
  if(!empty($_POST))
{
    $this->titre           = ($_POST['titre']);
    $this->description     = ($_POST['description']);
    $this->techno          = ($_POST['techno']);
    $this->comment         = ($_POST['comment']);
    $this->liens           = ($_POST['liens']);
    $this->image           = ($_FILES['image']['name']);
    $this->imagePath       = '../cv/public/images/' . basename($this->image);
    $this->imageExtension  = pathinfo($this->imagePath, PATHINFO_EXTENSION);
    $this->isSuccess       = true;
    $this->isUploadSuccess = false;
 
 
if(empty($this->titre)){
        $this->titreError = 'Ce champ ne peut pas etre vide';
        $this->isSuccess     = false;
         
      }
 
 if(empty($this->description)){
        $this->descriptionError = 'Ce champ ne peut pas etre vide';
        $this->isSuccess     = false;
          
      }
  if(empty($this->techno)){
        $this->technoError = 'Ce champ ne peut pas etre vide';
       $this->isSuccess    = false;
        
      }
   if(empty($this->comment)){
        $this->commentError = 'Ce champ ne peut pas etre vide';
       $this->isSuccess    = false;
        
      }   
      if(empty($this->liens)){
        $this->liensError = 'Ce champ ne peut pas etre vide';
        $this->isSuccess     = false;
        
      }  
      if(empty($this->image)){
        $this->imageError = 'Ce champ ne peut pas etre vide';
       $this->isSuccess     = false;
     
      }else
    {
        $this->isUploadSucces = true;
        if($this->imageExtension != "jpg" && $this->imageExtension != "png" && $this->imageExtension != "jpeg" && $this->imageExtension != "gif")
        {
            $this->imageError = "Les fichiers autorisés sont: .jpg, .jpeg, .png, .gif";
            $this->isUploadSuccess = false;
        }
        if(file_exists($this->imagePath))
        {
            $this->imageError = "Le fichier existe déja";
            $this->isUploadSuccess = false;
        }
        if($_FILES["image"]["size"] > 500000)
        {
            $this->imageError = "Le fichier ne doit pas dépasser les 500KB";
            $this->isUploadSuccess = false;
        }
        if($this->isUploadSuccess)
        {
            if(!move_uploaded_file($_FILES["image"]["tmp_name"], $this->imagePath))
            {
            $this->imageError = "Il y a eu une erreur lors de l'upload";
            $this->isUploadSuccess = false;
            }
 
      } 
    }    
       if($this->isSuccess && $this->isUploadSuccess)
    {
 
      $view = new View('portfolioInsert');
      $view->generer(['titreError'=>$this->titreError, 'descriptionError'=>$this->descriptionError, 'technoError'=>$this->technoError, 'commentError'=>$this->commentError,'imageError'=>$this->imageError,'liensError'=>$this->liensError,'titre'=>$this->titre,'description'=>$this->description,'techno'=>$this->techno,'comment'=>$this->comment,'image'=>$this->image,'liens'=>$this->liens,'isSuccess'=>$this->isSuccess]);
 
       $commentManager = new \Forteroche\Blog\Model\CommentManager();
        $portfolio = $commentManager->insertfolio($image, $description, $techno, $comment, $titre, $liens);
    header('location:index.php?action=portfolioInsert');
     
}
     
   
}
 
}


ma page:
<?php  include "menu.php" ;
 
?>
<br><br><br><br>
        <div class="container admin">
            <div class="row">
               
                <h1><strong>Ajouter un projet </strong></h1>
                    <br>
                    <form class="form" role="form" action="index.php?action=portfolioInsertAction" method="post" enctype="multipart/form-data">
                         <div class="form-group">
                        <label for="titre">Titre:</label>
                        <input type="text" class="form-control" id="titre" name="titre" placeholder="Titre" value="">
                             <span class="help-inline"><?php echo $titreError ;?></span>
                             <?php var_dump($titreError) ;?>
                             <?php var_dump($isSuccess) ;?>
                             <?php var_dump($titre) ;?>
                        </div> 
                          <div class="form-group">  
                        <label for="description">Description:</label>
                        <input type="text" class="form-control" id="description" name="description" placeholder="Description" value="">
                             <span class="help-inline"><?php echo $descriptionError ;?></span>
                        </div>
 
 
          
                        <div class="form-group">
                        <label for="techno">technologies:</label>
                        <input type="" step="" class="form-control" id="" name="techno" value="">
                             <span class="help-inline"><?php echo $technoError ;?></span>
 
                        </div>
 
                        <div class="form-group">
                        <label for="comment">Commentaire:</label>
                        <input type="" step="" class="form-control" id="" name="comment" value="">
                             <span class="help-inline"><?php echo $commentError ;?></span>
                        </div>
                         
                        <div class="form-group">
                        <label for="image">Sélectionner une image:</label>
                        <input type="file" id="image" name="image">
                        <span class="help-inline"><?php echo $imageError ;?></span>
                        </div>
                        <!--<div class="form-group">  
                        <label for="description">image:</label>
                        <input type="text" class="form-control" id="description" name="image" placeholder="Description" value="image">
                             <span class="help-inline"></span>
                        </div>-->
                    <div class="form-group">  
                        <label for="liens">liens:</label>
                        <input type="text" class="form-control" id="description" name="liens" placeholder="liens" value="">
                             <span class="help-inline"><?php echo $liensError ;?></span>
                        </div>
                    <br>
                    <div class="form-actions">
                    <button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-pencil"></span> Ajouter</button>
                    <a class="btn btn-primary" href="index.php"><span class="glyphicon glyphicon-arrow-left"> Retour</span></a>
                    </div>
                </form>
                <br> <br>
                 
             
            </div>
         
        </div>

Merci de votre aide!!


2 réponses

yg_be Messages postés 22773 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 9 mai 2024 1 481
6 avril 2018 à 19:39
bonsoir, je ne vois dans ton code ni catch, ni affichage des messages.
0
europe21 Messages postés 63 Date d'inscription mardi 26 décembre 2017 Statut Membre Dernière intervention 4 février 2024
6 avril 2018 à 20:00
Le catch est dans mon routeur. J'ai pas mis tout le code de mon routeur.Les messages des champs vide sont dans mon contrôleur dans des variables error.
0
yg_be Messages postés 22773 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 9 mai 2024 1 481 > europe21 Messages postés 63 Date d'inscription mardi 26 décembre 2017 Statut Membre Dernière intervention 4 février 2024
Modifié le 6 avril 2018 à 20:31
que penses-tu que fait la ligne 68? tu n'as pas expliqué ce que tu souhaitais faire, il est donc difficile de te dire si ton code fait ce que tu souhaites.
tu ne dis pas non plus pourquoi le catch déclenche.
0
europe21 Messages postés 63 Date d'inscription mardi 26 décembre 2017 Statut Membre Dernière intervention 4 février 2024
6 avril 2018 à 20:24
Cest bon j'ai trouvé !! le problème était a la fin dans le controller:
if($this->isSuccess && $this->isUploadSuccess) {
    $commentManager = new \Forteroche\Blog\Model\CommentManager();
    $portfolio = $commentManager->insertfolio($image, $description, $techno, $comment, $titre, $liens);
    header('location:index.php?action=portfolioInsert');
    exit();
} else {
    $view = new View('portfolioInsert');
    $view->generer(
        [
            'titreError'=>$this->titreError,
            'descriptionError'=>$this->descriptionError,
            'technoError'=>$this->technoError,
            'commentError'=>$this->commentError,
            'imageError'=>$this->imageError,
            'liensError'=>$this->liensError,
            'titre'=>$this->titre,
            'description'=>$this->description,
            'techno'=>$this->techno,
            'comment'=>$this->comment,
            'image'=>$this->image,
            'liens'=>$this->liens,
            'isSuccess'=>$this->isSuccess
        ]
    );
}
0