Comment soumettre les données du formulaire sur lequel on clique
jamjam100
Messages postés
2
Date d'inscription
Statut
Membre
Dernière intervention
-
jamjam100 Messages postés 2 Date d'inscription Statut Membre Dernière intervention -
jamjam100 Messages postés 2 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Je n'arrive pas à récupérer les données du formulaire sur lequel je clique. Si quelqu'un a une idée, ce serait vraiment cool. Voici mon code :
fichier forms.php
fichier processing.php
Je n'arrive pas à récupérer les données du formulaire sur lequel je clique. Si quelqu'un a une idée, ce serait vraiment cool. Voici mon code :
fichier forms.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title> Test formulaires </title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('form.myFormClass').on('submit', function(){ var id = this.id; var gidval = $("input[id^=gid]", this).val(); var prenom = $("input[id^=prenom]", this).val(); var nom = $("input[id^=nom]", this).val(); var email = $("input[id^=email]", this).val(); $.post("processing.php", { id: id, gid: gidval, prenom: prenomval, nom: nomval, email: emailval }, function(data) { $("#share p").html(data); }); return false; }); }); </script> </head> <body> Formulaire 1234 <form id="1234" class="myFormClass" method="post"> <input type="hidden" id="gid_1234" class="gid" value="1234" /> <p>Prénom: <input type="text" id="prenom_1234" class="prenom"/></p> <p>Nom: <input type="text" id="nom_1234" class="nom"/></p> <p>Email: <input type="text" id="email_1234" class="email"/></p> <p><input type="submit" value="Envoyer" /></p> </form> Formulaire 9876 <form id="9876" class="myFormClass" method="post"> <input type="hidden" id="gid_9876" class="gid" value="9876" /> <p>Prénom: <input type="text" id="prenom_9876" class="prenom"/></p> <p>Nom: <input type="text" id="nom_9876" class="nom"/></p> <p>Email: <input type="text" id="email_9876" class="email"/></p> <p><input type="submit" value="Envoyer" /></p> </form> <div id="share"> <p>résultat ici</p> </div> </body> </html>
fichier processing.php
<?php $id = $_POST['id']; $gid = 'gid_'; $gid .= $id; $prenom = 'prenom_'; $prenom .= $id; $nom = 'nom_'; $nom .= $id; $email = 'email_'; $email .= $id; echo $_POST[$gid]; echo '<br/>'; echo $_POST[$prenom]; echo '<br/>'; echo $_POST[$nom]; echo '<br/>'; echo $_POST[$email]; echo '<br/>'; ?>
A voir également:
- Comment soumettre les données du formulaire sur lequel on clique
- Whatsapp formulaire opposition - Guide
- Fuite données maif - Guide
- Formulaire de réclamation facebook - Guide
- Effacer les données de navigation sur android - Guide
- Formulaire de reclamation instagram - Guide
1 réponse
Voici le code qui fonctionne. ça peut toujours servir :
fichier forms.php
<gras>fichier processing.php<gras>
fichier forms.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title> Test formulaires </title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('form.myFormClass').on('submit', function(){ var id = this.id; var gidval = $("input[id^=gid_"+id+"]", this).val(); var prenomval = $("input[id^=prenom_"+id+"]", this).val(); var nomval = $("input[id^=nom_"+id+"]", this).val(); var emailval = $("input[id^=email_"+id+"]", this).val(); $.post("processing.php", { id: id, gid: gidval, prenom: prenomval, nom: nomval, email: emailval }, function(data) { $("#share p").html(data); }); return false; }); }); </script> </head> <body> Formulaire 1234 <form id="1234" class="myFormClass" method="post"> <input type="hidden" id="gid_1234" class="gid" value="1234" /> <p>Prénom: <input type="text" id="prenom_1234" class="prenom"/></p> <p>Nom: <input type="text" id="nom_1234" class="nom"/></p> <p>Email: <input type="text" id="email_1234" class="email"/></p> <p><input type="submit" value="Envoyer" /></p> </form> Formulaire 9876 <form id="9876" class="myFormClass" method="post"> <input type="hidden" id="gid_9876" class="gid" value="9876" /> <p>Prénom: <input type="text" id="prenom_9876" class="prenom"/></p> <p>Nom: <input type="text" id="nom_9876" class="nom"/></p> <p>Email: <input type="text" id="email_9876" class="email"/></p> <p><input type="submit" value="Envoyer" /></p> </form> <div id="share"> <p>résultat ici</p> </div> </body> </html>
<gras>fichier processing.php<gras>
<?php echo 'ID : '; echo $_POST['id']; echo '<br/>'; echo 'Prenom : '; echo $_POST['prenom']; echo '<br/>'; echo 'Nom : '; echo $_POST['nom']; echo '<br/>'; echo 'Email : '; echo $_POST['email']; echo '<br/>'; ?>