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

Langage PHP Discussion :

Récupération de données d'un formulaire


Sujet :

Langage PHP

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juillet 2017
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Brazzaville

    Informations professionnelles :
    Activité : Webmaster
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Juillet 2017
    Messages : 2
    Points : 1
    Points
    1
    Par défaut Récupération de données d'un formulaire
    Bonjour

    j' ai un problème avec mon code je travaille sur un projet et j aimerai résoudre ce problème

    voici le code de ma forme les champs sont dans un tableau, mais quand je clic sur le bouton valider le code php ne recupere pas les valeurs des champs vous trouverez le code php du bouton valider un peu plus bas.

    Code html : 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
    <form action="carriere.php" method="post" enctype="multipart/form-data" target="_self">
     
    						<table class="art-article" style="width: 100%; ">						
    						<tbody>											
    						<tr><td style="width: 100%; " colspan="2"><br>
    						<font color="black" size="3px">Civilité&nbsp;<span style="color: rgb(255, 0, 0); font-weight: bold; ">*&nbsp;</span>:<br>
    						<select  NAME="textchoix1" required>
    						<option selected>choisissez..</option>
    						<option value="Mr" checked>Mr</option>
    						<option value="Mm">Mm</option>
    						<option value="Mlle">Mlle</option>
    						</select></font>
    						<br></td></tr>
    						<tr><td style="width: 50%; "><font color="black" size="3px">Nom&nbsp;<span style="color: rgb(255, 0, 0); font-weight: bold; ">* &nbsp;</span>: 
    						<br><INPUT NAME="textnom" VALUE="" SIZE=30 required></font>
    						<br></td>
    						<td style="width: 50%; "><font color="black" size="3px">Prénom&nbsp;<span style="color: rgb(255, 0, 0); font-weight: bold; ">*&nbsp;</span>:
    						<br><INPUT NAME="textprenom" VALUE="" SIZE=30 required></font><br></td>
    						</tr>
    						<tr><td style="width: 50%; "><font color="black" size="3px">Téléphone&nbsp;<span style="color: rgb(255, 0, 0); font-weight: bold; ">*&nbsp;</span>:
    						<br><INPUT NAME="texttel" type="text" placeholder="Exemple:068630644" min=0 maxlength="9" id="tel" onchange="verif_tel()" SIZE=30 required></font><br></td>
    						<td style="width: 50%; "><font color="black" size="3px">E-mail&nbsp;<span style="color: rgb(255, 0, 0); font-weight: bold; ">*&nbsp;</span>:
    						<br><INPUT type="textemail" NAME="email" VALUE="" SIZE=30 required></font><br></td>
    						</tr>
    						<tr>
    						<td style="width: 50%; "><font color="black" size="3px">Adresse&nbsp;<span style="color: rgb(255, 0, 0); font-weight: bold; ">*&nbsp;</span>:
    						<br><INPUT NAME="textadr" VALUE="" SIZE=30 required></font><br></td>
    						<td style="width: 50%; "><font color="black" size="3px">Ville&nbsp;<span style="color: rgb(255, 0, 0); font-weight: bold; ">*&nbsp;</span>: 
    						<br><INPUT NAME="textville" VALUE="" SIZE=30 required></font><br></td>
    						</tr>
    						<tr><td style="width: 100%; " colspan="2"><br><font color="black" size="3px"><legend>Votre candidature :</legend></font>
    						<br><font color="black" size="3px">Motif de votre candidature<span style="color: rgb(255, 0, 0); font-weight: bold; ">*</span>&nbsp;:
    						<br><select  NAME="textchoix2" required>
    						<option  selected>précisez.</option>
    						<option value="Recherche_emploi">Recherche d'emploi</option>
    						<option value="Recherche_stage">Recherche de stage</option>
    						</select></font>
    						<br></td>
    						</tr>
    						<tr><td style="width: 100%; " colspan="2"><font color="black" size="3px"><legend><br></legend><legend>Votre curriculum vitea :</legend><legend><br></legend>
    						<legend>Votre motivation :
    						<br><textarea placeholder="veuillez choisir l'une des motivation suivantes: Je suis dynamique, je suis travailleur, je suis ambitieux, je suis bavard, je suis provocateur, je suis insupportable)" name="textlettre" cols=70 rows=8 ></textarea></legend></font><br>
    						</td></tr><tr><td style="width: 100%; " colspan="2"><font color="black" size="3px"><font color="black" size="3px">Votre curriculum vitea<span style="color: rgb(255, 0, 0); font-weight: bold; ">*</span> :
    						<INPUT TYPE="file" NAME="textfichier" SIZE="50" required></font></font><br></td>
    						</tr><tr>
    						<td style="width: 100%; " colspan="2">&nbsp;
    						<INPUT TYPE=SUBMIT name="carriere" VALUE="Envoyer" class="art-button">&nbsp;<input type="reset" value="Initialiser" class="art-button"/>
    						<!--<a href="" class="art-button">Envoyer</a>&nbsp;<a href="" class="art-button">Initialiser</a>&nbsp;-->
    						</td></tr>
     
    						</tbody>						
    						</table>
     
    						</form>

    execution du code php apres le clic sur le bouton valider
    Code php : 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
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    <?php
    if(isset($_POST['email'])) {
     
        // EDIT THE 2 LINES BELOW AS REQUIRED
        $email_to = "j.bouka@de-network.fr";
        $email_subject = "Information Carriere venant du site De-Network";
     
        function died($error) {
            // your error code can go here
            echo "We are very sorry, but there were error(s) found with the form you submitted. ";
            echo "These errors appear below.<br /><br />";
            echo $error."<br /><br />";
            echo "Please go back and fix these errors.<br /><br />";
            die();
        }
     
     
        // validation expected data exists
        if(!isset($_POST['textchoix1']) ||
            !isset($_POST['textnom']) ||
    		!isset($_POST['textprenom']) ||
    		!isset($_POST['texttel']) ||
            !isset($_POST['email']) ||
    		!isset($_POST['textadr']) ||
            !isset($_POST['textville']) ||
    		!isset($_POST['textchoix2']) ||
    		!isset($_POST['textlettre']) ||
            !isset($_POST['textfichier'])) {
            died('We are sorry, but there appears to be a problem with the form you submitted.');       
        }
     
     
     
        $Civilite = $_POST['textchoix1']; // required
        $nom = $_POST['textnom']; // required
    	$prenom = $_POST['textprenom']; // required
    	$telephone = $_POST['texttel']; // required
        $email_from = $_POST['email']; // required
        $adresse = $_POST['textadr']; // not required
        $ville = $_POST['textville']; // required
    	$candidature = $_POST['textchoix2']; // required
    	$lettre = $_POST['textlettre']; // required
    	$fichier = $_POST['textfichier']; // required
     
     
        $error_message = "";
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
     
      if(!preg_match($email_exp,$email_from)) {
        $error_message .= 'L  Adresse mail est invalide .<br />';
      }
     
        $string_exp = "/^[A-Za-z .'-]+$/";
     
      if(!preg_match($string_exp,$Civilite)) {
        $error_message .= ' La Civilité est incorrect.<br />';
      }
     
      if(!preg_match($string_exp,$nom)) {
        $error_message .= 'Le nom est incorrect.<br />';
      }
     
      if(!preg_match($string_exp,$prenom)) {
        $error_message .= 'Le prénom est invalide.<br />';
      }
     
      if(!preg_match($string_exp,$telephone)) {
        $error_message .= 'Le numero de telephone est invalide.<br />';
      }
     
      if(!preg_match($string_exp,$adresse)) {
        $error_message .= 'L adresse est invalide.<br />';
      }
     
      if(!preg_match($string_exp,$ville)) {
        $error_message .= 'Le nom de la ville est incorrect.<br />';
      }
     
      if(!preg_match($string_exp,$candidature)) {
        $error_message .= 'La Candidature est invalide.<br />';
      }
     
      if(strlen($lettre) < 2) {
        $error_message .= 'The Comments you entered do not appear to be valid.<br />';
      }
     
      if(strlen($error_message) > 0) {
        died($error_message);
      }
     
        $email_message = "Form details below.\n\n";
     
     
        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        }
     
     
        $email_message .= "Civilité: ".clean_string($Civilite)."\n";
        $email_message .= "Nom: ".clean_string($nom)."\n";
    	$email_message .= "Prénom: ".clean_string($prenom)."\n";
    	$email_message .= "Telephone: ".clean_string($telephone)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "Adresse: ".clean_string($adresse)."\n";
    	$email_message .= "Ville: ".clean_string($ville)."\n";
    	$email_message .= "Candidature: ".clean_string($candidature)."\n";
    	$email_message .= "Lettre de Motivation: ".clean_string($lettre)."\n";
        $email_message .= "C.V: ".clean_string($fichier)."\n";
     
    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);  
    ?>
     
    <!-- include your own success html here -->
     <script language="JavaScript" type="text/JavaScript">
    									alert("Votre message à bien été envoyé");
    									window.location.href="contact.php";
    									</script>
     
    <?php
     
    }
    ?>

  2. #2
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    16 959
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 16 959
    Points : 44 122
    Points
    44 122
    Par défaut
    Bonjour,
    commence par mettre un var_dump($_POST) pour vérifier ce que tu reçois coté serveur.

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juillet 2017
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Brazzaville

    Informations professionnelles :
    Activité : Webmaster
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Juillet 2017
    Messages : 2
    Points : 1
    Points
    1
    Par défaut
    Bonjour,

    on utilisant la balise $_POST['email']
    j' arrive a communiquer avec le serveur, mais ne récupère pas les informations contenues les champs. c est la mon problème

    les champs étant dans une table je n arrive pas a les extraire.

    Merci

  4. #4
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 551
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 551
    Points : 21 607
    Points
    21 607
    Par défaut
    Citation Envoyé par jay-jay21 Voir le message
    on utilisant la balise $_POST['email']
    j' arrive a communiquer avec le serveur,
    Cela ne veut absolument rien dire. On t'a dit de faire un var_dump($_POST);
    Est-ce que tu as fait ça, oui ou non ?

    Citation Envoyé par jay-jay21 Voir le message
    mais ne récupère pas les informations contenues les champs. c est la mon problème
    Ton problème c'est que tu ne connais pas les noms de tes propres champs. Fais un var_dump($_POST);

    Citation Envoyé par jay-jay21 Voir le message
    les champs étant dans une table je n arrive pas a les extraire.
    Cela n'a tout simplement rien à voir. Table ou non c'est pareil, rien ne change.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  5. #5
    Modérateur
    Avatar de blueice
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2003
    Messages
    3 487
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2003
    Messages : 3 487
    Points : 5 134
    Points
    5 134
    Par défaut
    Uniformisent tes noms de variables pour commencer.
    Ensuite à aucun moment tu ne déclares $Civilite $nom $prenom, c'est donc normal que tu n'ai rien.
    Rajoute "error_reporting(E_ALL)" pour être sûr d'avoir toutes les erreurs.
    ET comme dis plus haut fait un var_dump($_POST) !!
    -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_SIGNATURE -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
    Dans la mesure du possible, essayez de montrer votre problème en situation réelle en nous donnant une url, que l'on puisse tester.
    Pensez également à cocher

    Aucun problème ne doit être résolu en MP (Message Privé) le forum est là pour ça.

    Dimension Internet

  6. #6
    Modérateur
    Avatar de Vil'Coyote
    Homme Profil pro
    Développeur adélia & Web
    Inscrit en
    Février 2008
    Messages
    4 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur adélia & Web
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2008
    Messages : 4 583
    Points : 7 503
    Points
    7 503
    Par défaut
    en plus de se qu'indique blueice, tu devrais revoir l'html (type="textemail", manque de type sur des input etc ....)
    la vie n'est pas cirrhose des foies ...

    Avant de poster un message Rechercher n'est pas qu'une option.
    FAQ Web - Tuto Web

Discussions similaires

  1. [AJAX] Mon bouton onclick ne fonctionne pas
    Par geeka dans le forum AJAX
    Réponses: 2
    Dernier message: 17/04/2015, 15h09
  2. Mon bouton ne s'affiche pas correctement
    Par Splliter dans le forum Débuter
    Réponses: 5
    Dernier message: 11/05/2013, 01h01
  3. Mon bouton valide une mauvaise fonction ?!
    Par nico le noob dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 20/07/2010, 15h45
  4. mon bouton ne s'affiche pas
    Par naim2009 dans le forum Interfaces Graphiques
    Réponses: 1
    Dernier message: 29/12/2008, 14h13
  5. Mon bouton détail ne fonctionne pas
    Par cedric/copy dans le forum ASP
    Réponses: 3
    Dernier message: 22/07/2008, 14h43

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