[RESOLU] correction failed

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : [RESOLU] correction failed

correction failed

par le loup solitaire » 04 avr. 2016, 14:21

bonjours à tous,

j'ai un souci de correction, ce que je voudrai faire est que quand je remplie le champ text de la balise input et que je valide et bien tu me donne les bonnes ou mauvaises réponses....

j'ai pas d'erreur mais pas de correction?
<?php

function displaySelectReponse($choix)
    {
    $options = '';
    $select = "";
    foreach(explode(' ', $options) as $key => $option)
        {
        $select.= "<td><input type='text' name='$choix' value='$option' /></td>";
        }

    return $select;
    }

function displayReponse($choix)
    {
    global $errors, $reponses;
    $mot = $reponses[$choix]['mot'];
    $reponse_class = 'ok';
    $resultat = '';
    if (array_key_exists($choix, $errors))
        {
        $reponse_class = 'error';
        $resultat = " => " . $reponses[$choix]['reponse'];
        }

    $reponse = '<li class="' . $reponse_class . '">';
    $reponse.= '<span style="font-size:1.3em;" class="reponse">' . htmlspecialchars($_POST[$choix]) . '</span>
            <span style="margin-left:1%;font-size:1.3em;"">' . $mot . '</span>';
    $reponse.= ' <span style="color:red;font-size:1.3em;margin-left:5%;"" class="resultat">' . $resultat . '</span> ';
    $reponse.= '</li>';
    return $reponse;
    }

$form_ok = false;
$reponses = array(
    'chx_0' => array(
        'mot' => 'une',
        'reponse' => 'douche',
        'image' => 'img/douche.gif'
    ) ,
    'chx_1' => array(
        'mot' => 'une',
        'reponse' => 'poubelle',
        'image' => 'img/poubelle.gif'
    ) ,
    'chx_2' => array(
        'mot' => 'une',
        'reponse' => 'souris',
        'image' => 'img/souris.gif'
    ) ,
    'chx_3' => array(
        'mot' => 'une',
        'reponse' => 'soupe',
        'image' => 'img/soupe.gif'
    ) ,
    'chx_4' => array(
        'mot' => 'un',
        'reponse' => 'couteau',
        'image' => 'img/couteau.gif'
    ) ,
    'chx_5' => array(
        'mot' => 'un',
        'reponse' => 'tournevis',
        'image' => 'img/tournevis.gif'
    ) ,
    'chx_6' => array(
        'mot' => 'un',
        'reponse' => 'journal',
        'image' => 'img/journal.gif'
    ) ,
    'chx_7' => array(
        'mot' => 'une',
        'reponse' => 'carre-rouge',
        'image' => 'img/carré-rouge.gif'
    )
);

if (isset($_POST['correction']) && $_POST['correction'] === 'correction')
    {
    $empty = false;
    foreach($reponses as $key => $value)
        {
        if (empty($_POST[$key]))
            {
            $empty = true;
            }
        }

    if ($empty)
        {
        $msg = '<p>Veuillez cochez toutes les cases !</p>';
        echo $msg;
        }
      else
        {
        $form_ok = true;
        $errors = array();
        foreach($reponses as $key => $value)
            {
            if ($_POST[$key] == $value['reponse'])
                {
                $errors[$key] = htmlspecialchars($_POST[$key]);
                }
            }
        }
    }

?>
    <?php

if (!$form_ok)
    { ?>
            <form action="" method="POST" />
            
   <?php
    $images = array(
        '0' => array(
            'pronom' => 'une',
            'image' => 'img/douche.gif'
        ) ,
        '1' => array(
            'pronom' => 'une',
            'image' => 'img/poubelle.gif'
        ) ,
        '3' => array(
            'pronom' => 'une',
            'image' => 'img/souris.gif'
        ) ,
        '4' => array(
            'pronom' => 'une',
            'image' => 'img/soupe.gif'
        ) ,
        '5' => array(
            'pronom' => 'un',
            'image' => 'img/couteau.gif'
        ) ,
        '6' => array(
            'pronom' => 'un',
            'image' => 'img/tournevis.gif'
        ) ,
        '7' => array(
            'pronom' => 'un',
            'image' => 'img/journal.gif'
        ) ,
        '8' => array(
            'pronom' => 'un',
            'image' => 'img/rouge.gif'
        )
    );
    foreach($images as $key => $image)
        {
        foreach($reponses as $choix => $reponse)
            {
            if ($choix !== $reponse OR $image !== $reponse)
                {
                echo '<article class="content_img"><figure>';
                echo '<img src="' . $image['image'] . '" width="75" height="75" alt="" />';
                echo '</figure><p>' . $image['pronom'] . '</p>';
                echo displaySelectReponse($choix, $reponse['mot']);
                echo '</article>';
                break;
                }
            }
        }

?>         
            <input class="correction_center" type="submit" name="correction" value="correction"/>
            </form>
           
            
          
            <?php
    }
  else
    { ?>
            <p style="text-align:center;padding:4% 0 0 0;font-size:1.6em;font-weight:bold;display:block;" >Corrigé de l'exercice :</p>
            <div class="blc_reponses">
              <ol style="text-align:left;" class="reponses">
                <?php
    foreach($reponses as $choix => $value)
        {
        echo displayReponse($choix);
        } ?>
              </ol>
              <h2 style="display:inline-block;">Bonnes réponses :</h2>
              <p><?php
    echo count($reponses) - count($errors); ?> / <?php
    echo count($reponses); ?></p>
            </div>
            <div class="main_sec" style="text-align:center;margin-left:-10px;"> <span><a href="exo_ou_1.php">REFAIRE L'EXERCICE</a></span> <span><a href="exo_ou_2.php">EXERCICE SUIVANT</a></span> </div>
            <?php
    } ?>
merci d'avance