Jerry21
Messages postés104Date d'inscriptionmercredi 10 avril 2002StatutMembreDernière intervention 8 juin 2008
-
6 mars 2006 à 02:40
pastekk -
31 août 2010 à 13:47
Bonjour à tous,
Voilà je suis en train de créer un petit site internet pour une entreprise à but non lucratif, j'essai d'utiliser un code que j'ai trouvé sur l'internet la première partie est celle ci un fichier nommé form.html le code est :
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Achat de Cartons de Vin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
// <!-- <[CDATA[
function calculerPrix(champs, span) {
var prix;
prix = champs * 4.50;
prix = prix + '€';
document.getElementById(span).innerHTML = prix;
}
function calculerTotal(form, span) {
var cartons_vin1;
var cartons_vin2;
var cartons_vin3;
var total;
cartons_vin1 = form.cartons_vin1.value * 4.5;
cartons_vin2 = form.cartons_vin2.value * 4.5 ;
cartons_vin3 = form.cartons_vin3.value * 4.5;
total = Number(cartons_vin1) + Number(cartons_vin2) + Number(cartons_vin3);
document.getElementById(span).innerHTML = '= ' + total + '€';
}
// ]]> -->
</script>
</head>
<body>
<div id="contenu_principal">
<form method="post" action="traitement.php" id="cartons_vins">
<p><label for="Nom">Votre Nom : <input type="text" name="Nom" id="Nom" value="" /></label></p>
<p><label for="Prenom">Votre Prénom : <input type="text" name="Prenom" id="Prenom" value="" /></label></p>
<p><label for="Email">Votre email : <input type="text" name="Email" id="Email" value="" /></label></p>
<p><label for="Adresse">Votre adresse : <textarea name="Adresse" id="Adresse"></textarea></label></p>
<p><u>Vin 1</u></p>
<p><label for="cartons_vin1">Nombre de carton(s) souhaité(s) :
<input type="text" name="cartons_vin1" id="cartons_vin1" size="2" maxlength="2" onBlur="calculerPrix(this.value, 'affichage_prix-vin1')" value="0" /></label> x 4,50€ <span id="affichage_prix-vin1"> = 0.00€</span></p>
<p><u>Vin 2</u></p>
<p><label for="cartons_vin2">Nombre de carton(s) souhaité(s) :
<input type="text" name="cartons_vin2" id="cartons_vin2" size="2" maxlength="2" onBlur="calculerPrix(this.value, 'affichage_prix-vin2')" value="0" /></label> x 4,50€ <span id="affichage_prix-vin2"> = 0.00€</span></p>
<p><u>Vin 3</u></p>
<p><label for="cartons_vin3">Nombre de carton(s) souhaité(s) :
<input type="text" name="cartons_vin3" id="cartons_vin3" size="2" maxlength="2" onBlur="calculerPrix(this.value, 'affichage_prix-vin3');calculerTotal(this.form, 'affichage_total-vins')" value="0" /></label> x 4,50€ <span id="affichage_prix-vin3"> = 0.00€</span></p>
<p><strong>Total : </strong>
<span id="affichage_total-vins"> </span></p>
<p><input type="submit" value="Envoyer" /><input type="reset" value="Annuler" /></p>
</form>
</div>
</body>
</html>
Suivi d'une autre page nommée traitement.php le code est le suivant:
<?php
// Formulaire envoye ? Champs Vides ?
foreach($_POST as $champs => $valeur) {
if($champs != 'cartons_vin1' AND $champs != 'cartons_vin2' AND $champs != 'cartons_vin3') {
if(!isset($valeur) OR empty($valeur)) {
echo '<script type="text/javascript">// <![CDATA[',"\n",'alert("Veuillez remplir tous les champs.");',"\n",'window.location="form.html";',"\n",'// ]]>',"\n",'</script>';
}
}
}
// Declaration des variables
$Nom = trim(strip_tags($_POST['Nom']));
$Prenom = trim(strip_tags($_POST['Prenom']));
$Email = trim(strip_tags($_POST['Email']));
$Adresse = trim(strip_tags($_POST['Adresse']));
$NbreCartons['vin1'] = trim(strip_tags($_POST['cartons_vin1']));
$NbreCartons['vin2'] = trim(strip_tags($_POST['cartons_vin2']));
$NbreCartons['vin3'] = trim(strip_tags($_POST['cartons_vin3']));
$SousTotal['vin1'] = $NbreCartons['vin1'] * 4.5;
$SousTotal['vin2'] = $NbreCartons['vin2'] * 4.5;
$SousTotal['vin3'] = $NbreCartons['vin3'] * 4.5;
$Total = $SousTotal['vin1'] + $SousTotal['vin2'] + $SousTotal['vin3'];
?>
<?php echo '<','?xml version="1.0" encoding="ISO-8859-1" ?','>',"\n"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr-FR" dir="ltr">
<head xml:lang="fr-FR" dir="ltr">
<title>
Achat de Cartons de Vin - Récapitulatif de votre Commande
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<div id="contenu_principal">
<h3>Récapitulatif de vos Informations :</h3>
<p>Votre Nom : <strong><?php echo $Nom; ?></strong></p>
<p>Votre Prénom : <strong><?php echo $Prenom; ?></strong></p>
<p>Votre Adresse Email : <strong><?php echo $Email; ?></strong></p>
<p>Votre Adresse Postale : <strong><?php echo $Adresse; ?></strong></p>
<h3>Récapitulatif de votre Commande</h3>
<p>Vous avez commandé <?php echo ($NbreCartons['vin1'] == 1) ? "<strong>{$NbreCartons['vin1']}</strong> carton " : "{$NbreCartons['vin1']} cartons "; ?>du vin n°1, soit un total de <strong><?php echo $SousTotal['vin1']; ?></strong> €.</p>
<p>Vous avez commandé <?php echo ($NbreCartons['vin1'] == 1) ? "<strong>{$NbreCartons['vin2']}</strong> carton " : "{$NbreCartons['vin2']} cartons "; ?>du vin n°2, soit un total de <strong><?php echo $SousTotal['vin2']; ?></strong> €.</p>
<p>Vous avez commandé <?php echo ($NbreCartons['vin1'] == 1) ? "<strong>{$NbreCartons['vin3']}</strong> carton " : "{$NbreCartons['vin3']} cartons "; ?>du vin n°3, soit un total de <strong><?php echo $SousTotal['vin3']; ?></strong> €.</p>
<p style="font-weight: bold; color: #c00000;">Le total de votre commande s'élève donc à <strong><?php echo $Total; ?></strong> €.</p>
<p><a href="form.html">Modifier vos Informations</a> | <a href="javascript:print()">Imprimer cette Page</a>
</div>
</body>
</html>
Question 1: lorsque je met tout ces 2 pages sur mon serveur ftp et que j'accède à mon fichier ca ne fonctionne pas vous pouvez consulter vous même qu'est ce qui apparait lorsque vous appuyez sur soumettre. www3.sympatico.ca/tremblayjerome/form.html
En faite , la première page fonctionne très bien mais la seconde ne fonctionne pas bien, on dirait que le code php n'est pas reconnu merci de votre aide!!!!!!
ton code php est pas reconnu a cause de cette ligne:
<?php echo '<','?xml version="1.0" encoding="ISO-8859-1" ?','>',"\n"; [color=#FF0000]?>[/color]
ce que j'ais mis en rouge ne dois pas etre mis si tot sur ton script ,met le avant la ligne </body>,cela permettra au php de gérer les donner contenu entre <?php ...?>.
voila j'espère que cela va t'aider,en espérant que je ne me trompe pas.