Bonjour,
Voici le code de mon formulaire (il fonctionne très bien !). J'aimerais maintenant y ajouter la possibilité d'y insérer une pièce jointe, voir plusieurs... et je n'y arrive pas
======================================
Structure :
racine
- pj.html
- Confirm_pj.html
\php
- mail_pj.php
- mail_pj - validation_pj.php
\js
======================================
- verifications_pj.js
Voici mon code avec ce que j'ai déjà ajouter pour l'insertion des pièces jointes :
Fichier html (pj.html)
J'ai ajouté :
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
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 <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>ujju jyuj ujy u uyjuy juy | ASBL | 000000000 | </title> <meta http-equiv="content-Language" content="fr" /> <meta name="description" content="rth rh tyh tyh tyhtyhtyh tyhyh yh tht" /> <meta name="keywords" content="hy thyth h ththtyhty htyht htyhtyh tyhty htyh" /> <script> //Un generateur de mot de passe - par lecodejava.com var keylist="1234567890" var temp='' function generatepass(plength){ temp='' for (i=0;i<plength;i++) temp+=keylist.charAt(Math.floor(Math.random()*keylist.length)); return temp; } function populateform(enterlength){ document.pgenerate.output.value=generatepass(enterlength); } </script> <script type="text/javascript" src="js/verifications_pj.js"></script> <STYLE> A:unknown { font-family: Arial; font size="15"; COLOR: #000066; TEXT-DECORATION: underline } A:link { font-family: Arial; font size="15"; COLOR: #003399; TEXT-DECORATION: underline } A:visited { font-family: Arial; font size="15"; COLOR: #993300; TEXT-DECORATION: underline } A:active { font-family: Arial; font size="15"; COLOR: #003399; TEXT-DECORATION: none } A:hover { font-family: Arial; font size="15"; COLOR: #FF6600; TEXT-DECORATION: underline } body { background-color: #eaeff5; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } .Style1 {color: #993300} .Style2 {font-size: 10px} .Style3 { color: #FF0000; font-weight: bold; } </style> </head> <body> <div id="contener"> <table width="480" height="200" border="0" align="left" cellpadding="0" cellspacing="0" bordercolor="#0000CC" bgcolor="#eaeff5"> <tr> <td width="480" height="200" align="left" valign="top"> <form action="php/mail_pj.php" method="post" enctype="multipart/form-data" name="pgenerate"> <div align="left"></div> <table border="0" cellspacing="0" cellpadding="0" height="79"> <tr> <td width="100" height="30"><font size="2" class="Texte01">Nom : </font></td> <td width="380" height="30"> <input name="nom" type="text" id="nom" size="40"></td> </tr> <tr> <td height="30"><p><font size="2" class="Texte01">Email</font>:</p></td> <td height="30"><input name="mail" type="text" id="mail" size="40" /></td> </tr> <tr> <td height="19" colspan="2"> </td> </tr> </table> <table width="100%" border="0" cellpadding="0"> <tr> <td width="15%"><font size="2" class="Texte01">Captcha :</font></td> <td width="85%"><input type="text" name="output"style="border:0px;background-color:transparent;font-size:15pt;width:105px;height:28px;visibility:visible" disabled/> <input type="button" value="Générer un nouveau code" onClick="populateform(4)" /></td> </tr> <tr> <td> </td> <td><font size="2" class="Texte01">Entrez le code :</font> <input name="validationok" type="text" id="validationok" size="5" /></td> </tr> </table> Pièce jointe : <input name="pj" type="file" id="pj" size="30" /><br> <input type="submit" value="Envoyer le fichier" /><br> <table width="99%" border="0" cellpadding="0"> <tr> <td width="7%"> </td> </tr> </table> <p> <input type="button" value="Envoyer" onclick="verif(this.form);"/> <input type="reset" value="Effacer" /> </p> <script type="text/javascript"> populateform(4); </script> </form> </td> </tr> </table> </body> </html>
- enctype="multipart/form-data"
- <input name="pj" type="file" id="pj" size="30" /><br>
- <input type="submit" value="Envoyer le fichier" /><br>
Fichier html (Confirm_pj.html)
Fichier php (mail_pj.php)
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 <!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"> <head> <title>FORMULAIRE | SEP | 000000| </title> <meta http-equiv="content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="content-Language" content="fr" /> <meta name="description" content="get grtg rtgrtgrtgtr grt g trg rtg rtg" /> <meta name="keywords" content="gtrgrt gtrg rtgtrgtrgtrg rtg rtg trgtrg trgrtg " /> <meta http-equiv="Refresh" content="3;URL=pj.html"> <!--[if lt IE 7.]> <script defer type="text/javascript" src="js/pngfix.js"></script> <![endif]--> <title>Confirmation Formulaire</title> <style type="text/css"> <!-- body { background-color: #eaeff5; } .Style1 { color: #993300; font-weight: bold; font-size: 18px; } --> </style> </head> <body> <p class="Style1">Votre inscription a bien été envoyée !</p> <p><a href="pj.html" target="_self">Retour au formulaire </a></p> </body> </html>
Fichier js (verifications_pj.js)
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 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Refresh" content="0.1;URL=../Confirm_pj.html"> <title>Envoie du mail</title> </head> <body> <?php $nom=$HTTP_POST_VARS['nom']; $mail=$HTTP_POST_VARS['mail']; ; $email = 'formulaires@xxxx.com'; // c'est la personne qui recevra le message ! $email_reply = 'cihenrard@yxx.be'; // c'est la personne qui recevra le réponse ! $sujet ='Inscription'; $from = 'WebMaster'; // c'est le nom du contact qui sera affiché $from_mail = '$mail'; // c'est l'adresse à partir de laquelle le mail est envoyé, veillez à ce que l'adresse existe bien /////voici la version Mine $headers = 'Mime-Version: 1.0'."\r\n"; $headers .= 'Content-type: text/html; charset=utf-8'."\r\n"; $headers .= 'From: "INSCRIPTION"<'.$mail.'>'."\n"; $body= " <font color='#990033'>Journée <br />======================= 2015</font> <br />$nom <br /> "; mail($email,$sujet,$body, $headers); $email = $mail; // c'est la personne qui recevra le message ! $email_reply = 'formulaires@xxxxx.be'; // c'est la personne qui recevra le réponse ! $sujet ='Confirmation de l\'inscription'; $from = 'Formulaire'; // c'est le nom du contact qui sera affiché $from_mail = '$mail'; // c'est l'adresse à partir de laquelle le mail est envoyé, veillez à ce que l'adresse existe bien /////voici la version Mine $headers = 'Mime-Version: 1.0'."\r\n"; $headers .= 'Content-type: text/html; charset=utf-8'."\r\n"; $headers .= 'From: "INSCRIPTION"<'.$mail.'>'."\n"; $body= " <font color='#990033'>Journée <br />======================= 2015</font> <br />$nom <br /> "; mail($email,$sujet,$body, $headers); ?> </body> </html>
Fichier php (mail_pj - validation_pj.php)
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 function verif(f) { nom = f.nom.value; if (nom == "Nom *" || nom == "") { alert("Veuillez indiquer votre Nom !"); f.nom.focus(); return(false); } mail = f.mail.value; if (mail == "") { alert("Veuillez indiquer votre adresse de messagerie !"); f.mail.focus(); return(false); } validationok = f.validationok.value; output = f.output.value; if (validationok != output || validationok == "") { alert("Veuillez indiquer le bon code !"); f.validationok.focus(); return(false); } f.submit(); return(true); }
Ce morceau de code devrait être utilisé pour les pièces jointes, mais comment et ou et est-il complet ? Dois-je l'insérer au fichier js ?
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 <?php // Testons si le fichier a bien été envoyé et s'il n'y a pas d'erreur if (isset($_FILES['monfichier']) AND $_FILES['monfichier']['error'] == 0) { // Testons si le fichier n'est pas trop gros if ($_FILES['monfichier']['size'] <= 1000000) { // Testons si l'extension est autorisée $infosfichier = pathinfo($_FILES['monfichier']['name']); $extension_upload = $infosfichier['extension']; $extensions_autorisees = array('jpg', 'jpeg', 'gif', 'png'); if (in_array($extension_upload, $extensions_autorisees)) { } } } ?>
Pourriez-vous m'aider à compléter mon code pour qu'il puisse envoyer des pièces jointes ?
Grand merci d'avance :-)
Partager