<?php // La fonction demandee est presque "tableau_en_table" // sauf qu'il faut neutraliser les caracteres speciaux des saisies. error_reporting(E_ALL); include "../TME2/array_to.php"; function saisies_en_table($t, $legende) { $r = array(); // Le tableau etant des saisies de l'utilisateur // il faut se mefier de ce qu'il a pu ecrire comme "<" etc // y compris pour les index qui peuvent resulter d'une query-string ad hoc foreach ($t as $k => $v) { $r[htmlspecialchars($k)] = htmlspecialchars($v); } // A l'inverse, la legende etant fournie par le programmeur // on fait confiance aux chevrons qui y figurent, on ne transcode pas. // cf exemple ci-dessous return tableau_en_table($r, $legende); } // Test include '../TME2/entete.php'; echo entete("ShowForm"), "<body>"; $caption = '<strong>gjhjhcj</strong> : ' . htmlspecialchars($_SERVER['QUERY_STRING']); echo saisies_en_table($_GET, $caption); echo "</body></html>";
//require("../TME2/entete.php"); require 'ShowForm.php'; require 'controleSaisies.php'; define('RE_ETUDIANT', "/^[0-9]{7}\$/"); // definir une RegExp bout par bout: $re = '[A-Z]\\w*'; $re = "{$re}(-{$re})*"; # Ne pas écrire "/^$re[.]", PHP fait une erreur #si on veut [.] mettre "/^" . $r . "[.]..... $re = "{$re}\\.{$re}@\\w+(\\.\\w+)*"; define('RE_MAIL_ETENDU', "/^({$re})|([^<]*<{$re}>)\$/"); $mail = saisie_fiable($_POST, 'mail', RE_MAIL_ETENDU); $num = saisie_fiable($_POST, 'numEt', RE_ETUDIANT); $title = "Etudiant"; if ($mail === True and $num === True) { $body = saisies_en_table($_POST, "Informations"); } else { if ($mail === False or $num === False) { $title = "Erreur {$title}"; $mail = $_POST['mail']; $num = $_POST['numEt']; } $body = "<form action='' method='post'><fieldset>\n" . "<label for='numEt'>Numéro d'Étudiant :</label>" . "<input id='numEt' name='numEt' value='" . htmlspecialchars($num) . "' />\n" . "<label for='mail'>Mail :</label>" . "<input id='mail' name='mail' value='" . htmlspecialchars($mail) . "' />\n" . "<input type='submit' value='Envoyer'>\n" . "</fieldset></form>\n"; } echo entete($title), "<body><h1>{$title}</h1>\n", $body, "</body></html>\n"; //test $t = array('*****@*****.**', '"c\'est moi" <*****@*****.**>', '<i>@foo.bar'); echo $t[0], ' ', saisie_fiable($t, 0, RE_MAIL_ETENDU), "\n"; echo $t[1], ' ', saisie_fiable($t, 1, RE_MAIL_ETENDU), "\n"; echo $t[2], ' ', saisie_fiable($t, 2, RE_MAIL_ETENDU), "\n"; ?>
<?php error_reporting(E_ALL); require_once "../../TM/2/entete.php"; require_once 'ShowForm.php'; echo entete("Etudiant"); echo "<body>\n", "<h1>Etudiant</h1>\n"; if (isset($_POST['mail']) and isset($_POST['numEt'])) { echo saisies_en_table($_POST, "Informations"); } else { echo "<form action='' method='post'><fieldset>\n", "<label for='numEt'>Numéro d'Étudiant :</label>", "<input id='numEt' name='numEt' />\n", "<label for='mail'>Mail :</label>", "<input id='mail' name='mail' />\n", "<input type='submit' value='Envoyer'>\n", "</fieldset></form>\n"; } ?> </body> </html>