IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Erreur de variable lors de l'envoi du form


Sujet :

JavaScript

  1. #1
    Membre régulier Avatar de Lenezir
    Inscrit en
    Février 2006
    Messages
    129
    Détails du profil
    Informations personnelles :
    Âge : 37

    Informations forums :
    Inscription : Février 2006
    Messages : 129
    Points : 89
    Points
    89
    Par défaut Erreur de variable lors de l'envoi du form
    Salut.
    Je suis en train de me faire un site de e-commerce à la main et j'en suis au panier.
    Voici le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    <table>
    		<tr>
    			<th style="color : red;">&nbsp;*&nbsp;</th>
    
    			<th style="text-align : center;" colspan=2>&nbsp;Article&nbsp;</th>
    
    			<th style="text-align : center;">&nbsp;Description&nbsp;</th>
    
    			<th>&nbsp;Prix unitaire&nbsp;</th>
    			<th>&nbsp;Quantit&eacute;&nbsp;</th>
    			<th>&nbsp;Total&nbsp;</th>
    		</tr>
    
    		<?php
    
    			while($resultat_panier = mysql_fetch_array($execution_contenu_panier))
    
    			{
    
    		?>
    
    		<form method="post" name="panier" action="suppression_article_panier.php">
    		<tr>
    			<td style="text-align : center">
    				<a href="javascript:document.forms['panier'].submit()" style="font-weight : bold; color : red;">X</a>
    			</td>
    
    			<td>&nbsp;
    				<a href="enluminures/max/<?php echo $resultat_panier['image']; ?>" title="<?php echo $resultat_panier['titre']; ?>" rel="lightbox">
    					<img src="enluminures/min/<?php echo $resultat_panier['image']; ?>" />
    				</a>&nbsp;
    			</td>
    			<td style="font-weight : bold;">
    				<?php echo $resultat_panier['titre']; ?>&nbsp;
    			</td>
    
    			<td style="font-style : italic;">&nbsp;<?php echo $resultat_panier['description']; ?>&nbsp;</td>
    
    			<td style="color : red; text-align : right;">&nbsp;<?php echo $resultat_panier['prix']; ?>&nbsp;&euro;&nbsp;</td>
    
    			<td style="color : blue; text-align : center;">&nbsp;<?php echo $resultat_panier['quantite']; ?>&nbsp;</td>
    
    			<td style="font-weight : bold; color : red; text-align : right;">&nbsp;<?php $total_prix_article = $resultat_panier['quantite'] * $resultat_panier['prix']; echo $total_prix_article; ?>&nbsp;&euro;</td>
    
    			<input type="hidden" name="id_article" value="<?php echo $resultat_panier['id']; ?>" />
    
    			<?php
    
    				$total_commande = $total_commande + $total_prix_article;
    
    			?>
    		</tr>
    
    		</form>
    
    		<?php
    
    			}
    
    		?>
    	</table>
    Pour l'exemple, j'ai plusieurs articles dans le panier et je veux en supprimer un.
    J'ai donc un lien en JavaScript qui envoie le formulaire, et le script dans le "action" réceptionne la variable ID de l'article pour le supprimer.
    Ça marchait très bien en PHP, mais comme un gros bouton gris par ligne n'était pas esthétique, j'ai changé pour le lien JS.
    Seulement, quand je veux supprimer n'importe quelle ligne, il supprime toujours le dernier article ajouté. La variable ID envoyée est toujours la dernière entrée.
    Est-ce que vous auriez une idée pour faire en sorte que l'envoie du form envoie la bonne variable ?
    En espérant avoir été assez clair.
    Merci !

  2. #2
    Membre émérite
    Inscrit en
    Septembre 2002
    Messages
    2 307
    Détails du profil
    Informations forums :
    Inscription : Septembre 2002
    Messages : 2 307
    Points : 2 814
    Points
    2 814
    Par défaut
    document.forms['panier'].submit()
    trouve l'indice du "bon" formulaire

    mets un bouton submit!

  3. #3
    Rédacteur

    Avatar de Bovino
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2008
    Messages
    23 647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Points : 91 220
    Points
    91 220
    Billets dans le blog
    20
    Par défaut
    Ce serait plus pratique d'avoir le code HTML généré plutôt que le PHP mais bon...
    Ce n'est pas étonnant, à priori, tu crées autant de formulaires que d'articles mais qui ont tous le même nom, donc lorsque tu fais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <a href="javascript:document.forms['panier'].submit()" style="font-weight : bold; color : red;">X</a>
    c'est toujours le même qui est soumis...
    Pas de question technique par MP !
    Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
    Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
    Mon livre sur jQuery
    Module Firefox / Chrome d'intégration de JSFiddle et CodePen sur le forum

  4. #4
    Membre régulier Avatar de Lenezir
    Inscrit en
    Février 2006
    Messages
    129
    Détails du profil
    Informations personnelles :
    Âge : 37

    Informations forums :
    Inscription : Février 2006
    Messages : 129
    Points : 89
    Points
    89
    Par défaut
    Ah d'accord, je comprends mieux mon erreur.
    Je ne peux donc pas le faire en Javascript ?

    En attendant voici mon code généré :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    <table>
    		<tr>
    			<th style="color : red;">&nbsp;*&nbsp;</th>
    			<th style="text-align : center;" colspan=2>&nbsp;Article&nbsp;</th>
    			<th style="text-align : center;">&nbsp;Description&nbsp;</th>
    			<th>&nbsp;Prix unitaire&nbsp;</th>
     
    			<th>&nbsp;Quantit&eacute;&nbsp;</th>
    			<th>&nbsp;Total&nbsp;</th>
    		</tr>
    				<form method="post" name="panier" action="suppression_article_panier.php">
    		<tr>
    			<td style="text-align : center">
    				<a href="javascript:document.forms['panier'].submit()" style="font-weight : bold; color : red;">X</a>
     
    			</td>
    			<td>&nbsp;
    				<a href="enluminures/max/15.jpg" title="B" rel="lightbox">
    					<img src="enluminures/min/15.jpg" />
    				</a>&nbsp;
    			</td>
    			<td style="font-weight : bold;">
    				B&nbsp;
     
    			</td>
    			<td style="font-style : italic;">&nbsp;Le B enluminé&nbsp;</td>
    			<td style="color : red; text-align : right;">&nbsp;60&nbsp;&euro;&nbsp;</td>
    			<td style="color : blue; text-align : center;">&nbsp;10&nbsp;</td>
    			<td style="font-weight : bold; color : red; text-align : right;">&nbsp;600&nbsp;&euro;</td>
    			<input type="hidden" name="id_article" value="32" />
    					</tr>
     
    		</form>
    				<form method="post" name="panier" action="suppression_article_panier.php">
    		<tr>
    			<td style="text-align : center">
    				<a href="javascript:document.forms['panier'].submit()" style="font-weight : bold; color : red;">X</a>
    			</td>
    			<td>&nbsp;
    				<a href="enluminures/max/14.jpg" title="O" rel="lightbox">
     
    					<img src="enluminures/min/14.jpg" />
    				</a>&nbsp;
    			</td>
    			<td style="font-weight : bold;">
    				O&nbsp;
    			</td>
    			<td style="font-style : italic;">&nbsp;La lettre O enluminée&nbsp;</td>
    			<td style="color : red; text-align : right;">&nbsp;75&nbsp;&euro;&nbsp;</td>
     
    			<td style="color : blue; text-align : center;">&nbsp;7&nbsp;</td>
    			<td style="font-weight : bold; color : red; text-align : right;">&nbsp;525&nbsp;&euro;</td>
    			<input type="hidden" name="id_article" value="31" />
    					</tr>
    		</form>
    				<form method="post" name="panier" action="suppression_article_panier.php">
    		<tr>
    			<td style="text-align : center">
     
    				<a href="javascript:document.forms['panier'].submit()" style="font-weight : bold; color : red;">X</a>
    			</td>
    			<td>&nbsp;
    				<a href="enluminures/max/11.jpg" title="V" rel="lightbox">
    					<img src="enluminures/min/11.jpg" />
    				</a>&nbsp;
    			</td>
    			<td style="font-weight : bold;">
     
    				V&nbsp;
    			</td>
    			<td style="font-style : italic;">&nbsp;La lettre V enluminée&nbsp;</td>
    			<td style="color : red; text-align : right;">&nbsp;50&nbsp;&euro;&nbsp;</td>
    			<td style="color : blue; text-align : center;">&nbsp;4&nbsp;</td>
    			<td style="font-weight : bold; color : red; text-align : right;">&nbsp;200&nbsp;&euro;</td>
     
    			<input type="hidden" name="id_article" value="30" />
    					</tr>
    		</form>
    			</table>

  5. #5
    Rédacteur

    Avatar de Bovino
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2008
    Messages
    23 647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Points : 91 220
    Points
    91 220
    Billets dans le blog
    20
    Par défaut
    Si, c'est faisable en indentant une variable coté PHP afin de donner un nom différent à chaque formulaire, en mettant un bouton submit (il faut savoir qu'un input de type image est similaire à un submit) ou d'autres techniques.
    Pas de question technique par MP !
    Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
    Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
    Mon livre sur jQuery
    Module Firefox / Chrome d'intégration de JSFiddle et CodePen sur le forum

  6. #6
    Membre régulier Avatar de Lenezir
    Inscrit en
    Février 2006
    Messages
    129
    Détails du profil
    Informations personnelles :
    Âge : 37

    Informations forums :
    Inscription : Février 2006
    Messages : 129
    Points : 89
    Points
    89
    Par défaut
    J'ai compris ! \o/
    Je vais faire ça, merci pour ton aide !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [PHP 5.0] Erreur de header lors de l'envoi des cookies
    Par Kuchiki Byakuya dans le forum Langage
    Réponses: 3
    Dernier message: 17/03/2012, 02h24
  2. Réponses: 1
    Dernier message: 16/09/2009, 16h52
  3. Réponses: 2
    Dernier message: 04/02/2009, 20h50
  4. [VBA-E et Lotus]Erreur d'Automation lors de l'envoie du mail
    Par EvaristeGaloisBis dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 26/08/2008, 13h05
  5. [Mail] Erreur lors de l'envoi de mail
    Par PAYASS59 dans le forum Langage
    Réponses: 1
    Dernier message: 11/05/2006, 14h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo