Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/10/2010, 04:17
Estebam
 
Fecha de Ingreso: noviembre-2009
Mensajes: 13
Antigüedad: 14 años, 5 meses
Puntos: 1
Pregunta Ayuda para crear un $_POST funcional

Hola forer@s,

Os cuento que he creado un formulario de contacto para una escuela, en el formulario se pide que el usuario ponga alguna información basica y que elija con checkboxes el curso que le interesa.

El formulario funciona perfectamente usando esta forma de envio: <form action="sendmail.php" method="POST">; cuando reviso el correo se postea la información y los cursos que han sido elejidos con los checkboxes.

Tengo un solo problema, en el fichero "sendmail.php" utilizo echo para que muestre un mensaje donde aparezcan los datos que el usuario ha dejado en el formulario; todo funciona perfectamente excepto que el mensaje no muestra los cursos elejidos con los checkboxes.

Entiendo que el problema esta en la siguiente línea: echo "<p>Y Los Cursos Que Te Interesan: <b>".$_POST['check']."</b>.</p>";

Os agradecería, si alguien me puede echar una mano para escribir el codigo correctamente. A continuación os pongo el codigo de los dos archivos...

Formulario (contacto.html)
Código HTML:
<head>
<title>Formulario de Contacto</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.style2 {
	font-size: 12px;
	color: #660000;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	letter-spacing: 1pt;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
//-->
</script>
</head>
<body>
<table width="100%" height="761" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="88" bgcolor="#402000"></td>
  </tr>
  <tr>
    <td height="1" bgcolor="#996633"></td>
  </tr>
  <tr>
    <td height="549" align="center" bgcolor="#FFFFFF">
   <form action="sendmail.php" method="POST">   
      <br />
      <br />
      <table width="296" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="296" height="18" align="center" valign="top"><table width="266" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="266" height="266" align="left" valign="top"><span class="style2">Nombre:</span><br/>
                  <input name="Nombre" type="text" id="Nombre" size="35"/>
                  <p><span class="style2">Correo Electr&oacute;nico:</span> <span class="style2">* </span><br/>
                      <input name="Correo" type="text" id="Correo" size="35"/>
                  </p>
                <p><span class="style2">Tel&eacute;fono:</span><br/>
                      <input name="Telefono" type="text" id="Telefono" size="35"/>
                </p>
                <p><span class="style2">Comentarios:</span><br/>
                      <textarea name="message" cols="33" rows="5"></textarea>
                </p></td>
            </tr>
          </table>
          <br />
          </td>
        </tr>
        <tr>
          <td height="60" align="center" valign="top"><table width="296" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td height="27" colspan="3" align="center" valign="top"><p class="style2">Elije Los Cursos Que M&aacute;s Te Interesan:</p></td>
            </tr>
            <tr>
              <td width="92" height="170" align="left" valign="top"><p>
                  <input type="checkbox" name="check[]" value="Curso 1">
                  <span class="style2">Curso 1</span></p>
                  <p>
                    <input type="checkbox" name="check[]" value="Curso 2">
                    <span class="style2">Curso 2</span></p>
                <p>
                    <input type="checkbox" name="check[]" value="Curso 3">
                    <span class="style2">Curso 3</span></p>
                <p>
                    <input type="checkbox" name="check[]" value="Curso 4">
                    <span class="style2">Curso 4</span></p>
                <p>
                  <input type="checkbox" name="check[]" value="Curso 5">
                    <span class="style2">Curso 5</span></p></td>
              <td width="99" align="left" valign="top"><p>
                  <input type="checkbox" name="check[]" value="Curso 6">
                  <span class="style2">Curso 6</span></p>
                  <p>
                    <input type="checkbox" name="check[]" value="Curso 7">
                    <span class="style2">Curso 7</span></p>
                <p>
                    <input type="checkbox" name="check[]" value="Curso 8">
                    <span class="style2">Curso 8</span></p>
                <p>
                    <input type="checkbox" name="check[]" value="Curso 9">
                    <span class="style2">Curso 9</span></p>
                <p>
                    <input type="checkbox" name="check[]" value="Curso 10">
                    <span class="style2">Curso 10</span></p></td>
              <td width="105" align="left" valign="top"><p>
                  <input type="checkbox" name="check[]" value="Curso 11">
                  <span class="style2">Curso 11</span></p>
                  <p>
                    <input type="checkbox" name="check[]" value="Curso 12">
                    <span class="style2">Curso 12</span></p>
                <p>
                    <input type="checkbox" name="check[]" value="Curso 13">
                    <span class="style2">Curso 13</span></p>
                <p>
                    <input type="checkbox" name="check[]" value="Curso 14">
                    <span class="style2">Curso 14</span></p>
                <p>
                    <input type="checkbox" name="check[]" value="Curso 15">
                    <span class="style2">Curso 15</span></p></td>
            </tr>
          </table></td>
        </tr>
        <tr>
          <td align="center" valign="middle">
            <br />
            <p><input type="submit" onClick="MM_validateForm('Correo','','RisEmail');return document.MM_returnValue" value="Enviar"/></p>
            </td>
        </tr>
      </table>
      <br />
      <br />
   </form>
    </td>
  </tr>
  <tr>
    <td height="1" bgcolor="#996633"></td>
  </tr>
  <tr>
    <td height="78" bgcolor="#402000"></td>
  </tr>
</table>
</body> 
y respuesta (sendmail.php)

Código HTML:
<head>
<title>Formulario de Contacto</title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.style2 {
	font-size: 12px;
	color: #660000;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	letter-spacing: 1pt;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"></head>
<body>
<table width="100%" height="675" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="46" bgcolor="#402000"></td>
  </tr>
  <tr>
    <td height="1" bgcolor="#996633"></td>
  </tr>
  <tr>
    <td align="center" valign="middle" bgcolor="#FFFFFF"><table height="23" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td align="left" valign="top">
          <span class="style2">
          <?php
echo "<p>Gracias,<b>".$_POST["Nombre"]."</b>, Tu Correo Ha Sido Enviado.</p>";
echo "<p>Con Tu Direcci&oacute;n De Correo: <b>".$_POST["Correo"]."</b>,</p>";
echo "<p>Tu N&uacute;mero De Contacto: <b>".$_POST["Telefono"]."</b>,</p>";
echo "<p>Tus Comentarios: <b>".$_POST["message"]."</b>.</p>";
echo "<p>Y Los Cursos Que Te Interesan: <b>".$_POST['check']."</b>.</p>";
echo "<p><b>&iexcl;Nos Pondremos En Contacto!</b></p>";
//start building the mail string
$msg .= "Nombre:    ".$_POST["Nombre"]."\n";
$msg .= "Correo:  ".$_POST["Correo"]."\n";
$msg .= "Telefono:  ".$_POST["Telefono"]."\n";
$msg .= "Pedido o Comentario: ".$_POST["message"]."\n";

foreach($_POST['check'] as $value) {
$msg .= "Seleccionado: $value\n";

}

//set up the mail
$recipient = "[email protected]";
$subject = "Correo de Contacto";
$mailheaders = "From: Contacto de Mi Página Web <[email protected]> \n";
$mailheaders .= "Reply-To: ".$_POST["email"];
//send the mail
mail($recipient, $subject, $msg, $mailheaders);
?>
          </span></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="1" bgcolor="#996633"></td>
  </tr>
  <tr>
    <td height="78" bgcolor="#402000"></td>
  </tr>
</table>
</body>