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 :

[Mail] Envoyer valeur de plusieurs checkbox cochées à travers la fonction email


Sujet :

Langage PHP

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    72
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 72
    Points : 44
    Points
    44
    Par défaut [Mail] Envoyer valeur de plusieurs checkbox cochées à travers la fonction email
    Salut a tous,

    J'ai un petit problème je suis en train de développer un petit formulaire de contact avec des checkbox et je veux envoyer la valeur des différentes checkbox cochées mais je n'y arrive pas.

    Voici le code de la page

    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
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
     
    <?php
    $nome = $_POST["nome"];
    $empresa = $_POST["empresa"];
    $localidade = $_POST["localidade"];
    $email = $_POST["email"];
    $telefone = $_POST["telefone"];
    $mes = $_POST["mes"];
    $horario = $_POST["horario"];
    $curso = $_POST["curso"];
    $comentarios = $_POST["comentarios"];
    if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
    ?>
    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Pedido de Informações</title>
    <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
    <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
    <link href="main_askinfo.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <form method="post" action="<?php echo $PHP_SELF;?>">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><!--Inicio da tabela de Informações-->
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td colspan="2">Informação de Contacto</td>
              </tr>
              <tr>
                <td colspan="2">&nbsp;</td>
              </tr>
              <tr>
                <td>Nome: *</td>
                <td><span id="sprytextfield2">
     
                  <input type="text" name="nome" />
     
                  <span class="textfieldRequiredMsg">Campo obrigatório.</span></span></td>
              </tr>
              <tr>
                <td>Empresa: *</td>
                <td><span id="sprytextfield3">
     
                  <input type="text" name="empresa" />
     
                  <span class="textfieldRequiredMsg">Campo obrigatório.</span></span></td>
              </tr>
              <tr>
                <td>Localidade: *</td>
                <td><span id="sprytextfield1">
     
                  <input type="text" name="localidade" />
     
                  <span class="textfieldRequiredMsg">Campo obrigatório.</span></span></td>
              </tr>
              <tr>
                <td>E-mail: *</td>
                <td><span id="sprytextfield4">
     
                  <input type="text" name="email" />
     
                  <span class="textfieldRequiredMsg">Campo obrigatório.</span><span class="textfieldInvalidFormatMsg">Endereço de E-mail inválido.</span></span></td>
              </tr>
              <tr>
                <td>Tel: *</td>
                <td><span id="sprytextfield5">
     
                  <input type="text" name="telefone" />
     
                  <span class="textfieldRequiredMsg">Campo obrigatório.</span></span></td>
              </tr>
              <tr>
                <td colspan="2">&nbsp;</td>
              </tr>
            </table>
            <!--Fim da tabela de Informações-->
            <!--Inicio da tabela de Assinale a sua preferência-->
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td>Assinale a sua preferência</td>
              </tr>
              <tr>
                <td>Início do curso:</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td><!--Inicio da tabela de Selecção de mês-->
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td>Jan </td>
                      <td> 
                        <input type="checkbox" name="mes[]" value="Janeiro" />
                         </td>
                      <td>Fev </td>
                      <td> 
                        <input type="checkbox" name="mes[]" value="Fevereiro" />
                         </td>
                      <td>Março </td>
                      <td> 
                        <input type="checkbox" name="mes[]" value="Marco" />
                         </td>
                      <td>Abril</td>
                      <td> 
                        <input type="checkbox" name="mes[]" value="Abril" />
                         </td>
                      <td>Maio</td>
                      <td> 
                        <input type="checkbox" name="mes[]" value="Maio" />
                         </td>
                      <td>Jun </td>
                      <td> 
                        <input type="checkbox" name="mes[]" value="Junho" />
                         </td>
                    </tr>
                    <tr>
                      <td>Jul</td>
                      <td> 
                        <input type="checkbox" name="mes[]" value="Julho" />
                         </td>
                      <td>Ago</td>
                      <td> 
                        <input type="checkbox" name="mes[]" value="Agosto" />
     
                      </td>
                      <td>Set</td>
                      <td> 
                        <input type="checkbox" name="mes[]" value="Setembro" />
                         </td>
                      <td>Out</td>
                      <td> 
                        <input type="checkbox" name="mes[]" value="Outubro" />
                         </td>
                      <td>Nov</td>
                      <td> 
                        <input type="checkbox" name="mes[]" value="Novembro" />
                         </td>
                      <td>Dez</td>
                      <td> 
                        <input type="checkbox" name="mes[]" value="Dezembro" />
                         </td>
                    </tr>
                  </table>
                  <!--Fim da tabela de Selecção de mês-->
                </td>
              </tr>
              <tr>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>Horário:</td>
              </tr>
              <tr>
                <td><!--Inicio tabela horario-->
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td>Laboral  </td>
                      <td>
                        <input type="checkbox" name="horario[]" value="Laboral" />
                      </td>
                      <td>Pós-Laboral  </td>
                      <td>
                        <input type="checkbox" name="horario[]" value="Pós-laboral" />
                      </td>
                      <td>Sábado  </td>
                      <td>
                        <input type="checkbox" name="horario[]" value="Sábado" />
                      </td>
                    </tr>
                  </table>
                  <!--Fim tabela horario-->
                </td>
              </tr>
              <tr>
                <td>&nbsp;</td>
              </tr>
            </table>
            <!--Fim da tabela Assinale a sua preferência-->
            <!--Inicio da tabela areas de formação-->
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td>Áreas de Formação</td>
              </tr>
              <tr>
                <td><!--Inicio da tabela de selecção das áreas de formação-->
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td>Inglês</td>
                      <td>
                        <input type="checkbox" name="curso[]" value="Inglês" />
                      </td>
                      <td>Francês</td>
                      <td>
                        <input type="checkbox" name="curso[]" value="Francês" />
                      </td>
                      <td>Alemão</td>
                      <td>
                        <input type="checkbox" name="curso[]" value="Alemão" />
                      </td>
                      <td>Espanhol</td>
                      <td>
                        <input type="checkbox" name="curso[]" value="Espanhol" />
                      </td>
                      <td>Outras</td>
                      <td>
                        <input type="checkbox" name="curso[]" value="Outras" />
                      </td>
                    </tr>
                  </table>
                  <!--Fim da tabela de selecção das áreas de formação-->
                </td>
              </tr>
              <tr>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>Comentários</td>
              </tr>
              <tr>
                <td> 
                  <textarea name="comentarios" cols="45" rows="5"></textarea>
                   </td>
              </tr>
              <tr>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td><table width="30%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td> 
                        <input type="submit" value="submit" name="submit"></td>
                      <td>&nbsp;</td>
                    </tr>
                  </table></td>
              </tr>
            </table>
            <!--Fim da tabela areas de formação-->
          </td>
        </tr>
      </table>
    </form>
    <script type="text/javascript">
    var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
    var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
    var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "email");
    var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5");
    </script>
     
    <?
    } else {
    echo "<b><H2>Dados enviados via email.</b></H2><br />";
    echo "<b>Nome: </b>".$nome."<br />";
    echo "<b>Empresa: </b>".$empresa."<br />";
    echo "<b>Localidade: </b>".$localidade."<br />";
    echo "<b>Telefone: </b>".$telefone."<br /><br />";
    echo "<b>Preferência de início do curso</b><br />";
    foreach ($mes as $m) {
    echo $m."<br />";
    }
    echo "<br /><b>Escolha de horário:</b><br />";
    foreach ($horario as $h) {
    echo $h."<br />";
    }
    echo "<br /><b>Áreas de Formação</b><br />";
    foreach ($curso as $c) {
    echo $c."<br />";
    }
    $paraendereco = "helios25@gmail.com";
    $assunto      = "Pedido de informações sobre cursos";
    $conteudomail = "Informação de contacto"."\n\n"
    . "Seu nome: " . $nome . "\n\n"
    . "Empresa: " . $empresa . "\n\n"
    . "Localidade: " . $localidade . "\n\n\n"
    . "Email: " . $email . "\n\n\n"
    . "Telefone: " . $telefone . "\n\n\n"
    . "Preferência de início do curso:\n"
    foreach ($horario as $h) {
       .$h."\n";
      };
    "\n\n\n\n\Escolha de horário:"
    foreach ($horario as $h) {
       .$h."\n";
     }
    "\n\n\n\nreas de Formação"
    foreach ($curso as $c) {
       .$c."\n";
     }
    mail($paraendereco, $assunto, $conteudomail, "From: $email");
    }
    ?>
    Mon problème se passe sur ce bout de 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
     
    foreach ($horario as $h) {
       .$h."\n";
      };
    "\n\n\n\n\Escolha de horário:"
    foreach ($horario as $h) {
       .$h."\n";
     }
    "\n\n\n\nreas de Formação"
    foreach ($curso as $c) {
       .$c."\n";
     }
    mail($paraendereco, $assunto, $conteudomail, "From: $email");
    }
    Si j'utilise ça tel quel ça me donne une erreur:

    Parse error: parse error, unexpected T_FOREACH in /home/cs/uscho/www/askinformation.php on line 281


    Est-ce qu'il y a quelqu'un qui saurait comment est-ce que je pourrais faire pour pouvoir passer la valeur de toutes les checkbox qui sont cochées.

    Merci a tout.

  2. #2
    Membre éclairé Avatar de Korko Fain
    Profil pro
    Étudiant
    Inscrit en
    Août 2005
    Messages
    632
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2005
    Messages : 632
    Points : 718
    Points
    718
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    ;
    foreach ($horario as $h) {
       $conteudomail .= $h."\n";
      }
    $conteudomail .= "\n\n\n\n\Escolha de horário:";
    foreach ($horario as $h) {
       $conteudomail .= $h."\n";
     }
    $conteudomail .= "\n\n\n\nreas de Formação";
    foreach ($curso as $c) {
       $conteudomail .= $c."\n";
     }
    mail($paraendereco, $assunto, $conteudomail, "From: $email");
    }
    C'est mieux ainsi.

    Tu ne peux pas faire un foreach dans une affectation de variable

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    72
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 72
    Points : 44
    Points
    44
    Par défaut
    Je tiens vraiment a te remercier pour ton aide Korko Fain.

    Ça marche a merveille.

    Encore une foi un GROS MERCI.

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

Discussions similaires

  1. Réponses: 3
    Dernier message: 03/01/2012, 12h06
  2. récupérer et traiter les valeur de plusieur checkbox
    Par artichaudd dans le forum Langage
    Réponses: 11
    Dernier message: 26/12/2011, 18h23
  3. [Tableaux] Recuperer les valeurs de plusieurs checkbox
    Par tomenbois dans le forum Langage
    Réponses: 9
    Dernier message: 18/03/2008, 12h23
  4. Réponses: 5
    Dernier message: 18/02/2008, 16h11
  5. Réponses: 2
    Dernier message: 24/08/2007, 14h25

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