Foros del Web » Programando para Internet » PHP »

No me llegan todos los datos de mi formulario php

Estas en el tema de No me llegan todos los datos de mi formulario php en el foro de PHP en Foros del Web. Yo también tengo un problema con mi formulario php. Después de dejarme la piel para poder conseguir un formulario SUPER SENCILLO, recibo todo excepto edad ...
  #1 (permalink)  
Antiguo 28/03/2014, 04:18
 
Fecha de Ingreso: marzo-2014
Mensajes: 11
Antigüedad: 10 años, 1 mes
Puntos: 0
Pregunta No me llegan todos los datos de mi formulario php

Yo también tengo un problema con mi formulario php. Después de dejarme la piel para poder conseguir un formulario SUPER SENCILLO, recibo todo excepto edad y población. Por otra parte también me sale un $ en el asunto, debo haber tocado algo que no debía. Lo dejo aquí a ver si alguien ve los posibles errores:

mail("$email", "$prefijo $", "$contenido", "From: $f_name <$f_mail>");
echo "<em>Tu mensaje ha sido enviado. En breve nos pondremos en contacto contigo, gracias.</em>";
}
else {
if ($op<>"") { echo "<em>¡Ups! Es necesario rellenar correctamente todos los campos, gracias.</em>"; }

?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div align="center">
<table>
<tr>
<td width="19" height="43" align="right" bgcolor="#999999">&nbsp;</td>
<td width="745" align="left" bgcolor="#999999"><strong>Nombre y Apellidos</strong>
<input name="f_name" type="text" value="<?php echo $f_name; ?>" size="60" /></td>
</tr>
<tr>
<td height="38" align="right" bgcolor="#999999">&nbsp;</td>
<td align="left" bgcolor="#999999"><strong>E-mail</strong>
<input name="f_mail" type="text" value="<?php echo $f_mail; ?>" size="30" />
<strong> Edad </strong> <input name="f_Edad" type="text" value="<?php echo $f_Edad; ?>" size="10" /></td>
</tr>
<tr>
<td height="37" align="right" bgcolor="#999999">&nbsp;</td>
<td align="left" bgcolor="#999999"><strong>Población</strong> <input name="poblacion" type="text" value="<?php echo $poblacion; ?>" size="30" /></td>
</tr>
<tr>
<td height="243" align="right" bgcolor="#999999">&nbsp;</td>
<td align="left" bgcolor="#999999"><strong>Consulta</strong>
<p>
<textarea cols="80" rows="10" name="f_message"><?php echo $f_message; ?></textarea>
</p></td>
</tr>
<?php if ($pregunta) { ?>
<tr>
<td colspan="2" align="left" bgcolor="#999999"><?php echo $pregunta; ?> <input name="rs" type="text" value="" size="10" maxlength="10" /></td>
</tr>
<?php } else {echo "<input type='hidden' name='rs' value='rs' />";} ?>
</table>
<input type="hidden" name="op" value="ds" />
<input type="submit" value="Enviar consulta" />
</div>
</form>
<?php
}
?>


Esto es lo que tengo en form.php.
  #2 (permalink)  
Antiguo 28/03/2014, 08:06
 
Fecha de Ingreso: febrero-2011
Mensajes: 100
Antigüedad: 13 años, 2 meses
Puntos: 0
Respuesta: No me llegan todos los datos de mi formulario php

Si pasas lo valores en duro llegan?

<input name="poblacion" type="text" value="stgo" size="30" />
  #3 (permalink)  
Antiguo 30/03/2014, 10:51
fiu
 
Fecha de Ingreso: diciembre-2006
Ubicación: Barcelona
Mensajes: 128
Antigüedad: 17 años, 4 meses
Puntos: 8
Respuesta: No me llegan todos los datos de mi formulario php

has probado a hacer esto a ver qué llega y cómo?

Código PHP:
Ver original
  1. foreach( $_POST as $k => $v ) {
  2.     echo "<br />".$k." => ".$v;
  3. }
  #4 (permalink)  
Antiguo 31/03/2014, 02:11
 
Fecha de Ingreso: marzo-2014
Mensajes: 11
Antigüedad: 10 años, 1 mes
Puntos: 0
Respuesta: No me llegan todos los datos de mi formulario php

Cita:
Iniciado por roys1985 Ver Mensaje
Si pasas lo valores en duro llegan?

<input name="poblacion" type="text" value="stgo" size="30" />
Desgraciadamente necesito que aparezca en blanco el valor, he probado a poner lo que me dices, pero claro, aparece el valor escrito... Tendría que dejar algo así?:

<input name="poblacion" type="text" value="" size="30" />
  #5 (permalink)  
Antiguo 31/03/2014, 02:13
 
Fecha de Ingreso: marzo-2014
Mensajes: 11
Antigüedad: 10 años, 1 mes
Puntos: 0
Respuesta: No me llegan todos los datos de mi formulario php

Cita:
Iniciado por fiu Ver Mensaje
has probado a hacer esto a ver qué llega y cómo?

Código PHP:
Ver original
  1. foreach( $_POST as $k => $v ) {
  2.     echo "<br />".$k." => ".$v;
  3. }
Voy a probar! Dónde tengo que colocarlo? ejem, perdona mi ignorancia!!
  #6 (permalink)  
Antiguo 31/03/2014, 03:05
 
Fecha de Ingreso: marzo-2014
Mensajes: 11
Antigüedad: 10 años, 1 mes
Puntos: 0
Respuesta: No me llegan todos los datos de mi formulario php

A ver si así se ve un poco más claro el error:

Código PHP:
Ver original
  1. <?php
  2. ###### No edites este archivo ######
  3.  
  4. require "config.php";
  5.  
  6. # RegisterGlobals OFF
  7.  
  8. $f_name = $_POST['f_name'];
  9. $f_mail = $_POST['f_mail'];$f_Edad = $_POST['f_Edad'];
  10. $poblacion = $_POST['poblacion'];
  11. $f_message = $_POST['f_message'];
  12. $rs = $_POST['rs'];
  13. $op = $_POST['op'];
  14.  
  15.    
  16.     $f_name = stripslashes($f_name);
  17.     $f_mail = stripslashes($f_mail);
  18.     $f_Edad = stripslashes($f_Edad);
  19.     $poblacion = stripslashes($poblacion);
  20.     $f_message = stripslashes($f_message);
  21.     $rs = stripslashes($rs);
  22.     $op = stripslashes($op);
  23. }
  24.  
  25. # comprobamos que el formulario no esté vacío
  26.  
  27. if ($f_name <> "" and $f_mail <> ""and $f_Edad <> "" and $poblacion <> "" and $f_message <> "" and $rs <> "" and (ereg("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$",$f_mail))) {
  28.  
  29. // First, make sure the form was posted from a browser.
  30. // For basic web-forms, we don't care about anything
  31. // other than requests from a browser:    
  32. if(!isset($_SERVER['HTTP_USER_AGENT'])){
  33.    die("Acceso no autorizado");
  34.    exit;
  35. }
  36.  
  37. // Make sure the form was indeed POST'ed:
  38. //  (requires your html form to use: action="post")  
  39. if(!$_SERVER['REQUEST_METHOD'] == "POST"){
  40.    die("Acceso no autorizado");
  41.    exit;    
  42. }
  43.  
  44. // Where have we been posted from?
  45. $fromArray = parse_url(strtolower($_SERVER['HTTP_REFERER']));
  46.  
  47. // Test to see if the $fromArray used www to get here.
  48. $wwwUsed = strpos($fromArray['host'], "www.");
  49.  
  50. // Make sure the form was posted from an approved host name.
  51. if(!in_array(($wwwUsed === false ? $fromArray['host'] : substr(stristr($fromArray['host'], '.'), 1)), $authHosts)){    
  52.    die("Acceso no autorizado");  
  53.        exit;    
  54. }
  55.  
  56. // Pregunta antispam
  57.  
  58. if ($pregunta) {
  59. if ($rs != $respuesta) { die ("<em>¿Seguro que la respuesta es correcta? Vuelve atrás en tu navegador</em>");exit; }
  60. }
  61.  
  62. // Attempt to defend against header injections:
  63. $badStrings = array("Content-Type:",
  64.                     "MIME-Version:",
  65.                     "Content-Transfer-Encoding:",
  66.                     "bcc:",
  67.                     "Bcc:",
  68.                     "BCC:",
  69.                     "cc:",
  70.                     "Cc:",
  71.                     "CC:");
  72.  
  73. // Loop through each POST'ed value and test if it contains
  74. // one of the $badStrings:
  75. foreach($_POST as $k => $v){
  76.    foreach($badStrings as $v2){
  77.        if(strpos($v, $v2) !== false){
  78.                 die("Acceso no autorizado");
  79.                exit;
  80.        }
  81.    }
  82. }    
  83.  
  84. // Made it past spammer test, free up some memory
  85. // and continue rest of script:    
  86. unset($k, $v, $v2, $badStrings, $authHosts, $fromArray, $wwwUsed);
  87.  
  88. //contenido
  89.  
  90.    $informacion .= "\n\n------ información ------\n";
  91.  
  92.          $informacion .= "REMOTE HOST: ".$_SERVER['REMOTE_HOST']."\n";
  93.          $informacion .= "REMOTE ADDR: ".$_SERVER['REMOTE_ADDR']."\n";
  94.          $informacion .= "HTTP_X_FORWARDED_FOR: ".$_SERVER['HTTP_X_FORWARDED_FOR']."\n";
  95.          $informacion .= "HTTP_CLIENT_IP: ".$_SERVER['HTTP_CLIENT_IP']."\n";
  96.          $informacion .= "NAVEGADOR: ".$_SERVER['HTTP_USER_AGENT']."\n";
  97.  
  98.  
  99. $contenido = "$f_message
  100. $informacion
  101. ";
  102.  
  103.  
  104. mail("$email", "$prefijo $", "$contenido", "From: $f_name <$f_mail>");
  105. echo "<em>Tu mensaje ha sido enviado. En breve nos pondremos en contacto contigo, gracias.</em>";
  106. }
  107. else {
  108. if ($op<>"") { echo "<em>¡Ups! Es necesario rellenar correctamente todos los campos, gracias.</em>"; }
  109.  
  110. ?>
  111. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  112.   <div align="center">
  113.   <table>
  114.     <tr>
  115.       <td width="19" height="43" align="right" bgcolor="#999999">&nbsp;</td>
  116.       <td width="745" align="left" bgcolor="#999999"><strong>Nombre y Apellidos</strong>
  117.         <input name="f_name" type="text" value="<?php echo $f_name; ?>" size="60" /></td>
  118.       </tr>
  119.     <tr>
  120.       <td height="38" align="right" bgcolor="#999999">&nbsp;</td>
  121.       <td align="left" bgcolor="#999999"><strong>E-mail</strong>
  122. <input name="f_mail" type="text" value="<?php echo $f_mail; ?>" size="30" />
  123.         <strong> Edad </strong>        <input name="f_Edad" type="text" value="<?php echo $f_Edad; ?>" size="10" /></td>
  124.       </tr>
  125.     <tr>
  126.       <td height="37" align="right" bgcolor="#999999">&nbsp;</td>
  127.       <td align="left" bgcolor="#999999"><strong>Población</strong>        <input name="poblacion" type="text" value="<?php echo $poblacion; ?>" size="30" /></td>
  128.       </tr>
  129.     <tr>
  130.       <td height="243" align="right" bgcolor="#999999">&nbsp;</td>
  131.       <td align="left" bgcolor="#999999"><strong>Consulta</strong>
  132.         <p>
  133.   <textarea cols="80" rows="10" name="f_message"><?php echo $f_message; ?></textarea>
  134.         </p></td>
  135.       </tr>
  136.     <?php if ($pregunta) { ?>
  137.     <tr>
  138.       <td colspan="2" align="left" bgcolor="#999999"><?php echo $pregunta; ?> <input name="rs" type="text" value="" size="10" maxlength="10" /></td>
  139.       </tr>
  140.     <?php } else {echo "<input type='hidden' name='rs' value='rs' />";} ?>
  141.   </table>
  142.   <input type="hidden" name="op" value="ds" />
  143.   <input type="submit" value="Enviar consulta" />
  144.   </div>
  145. </form>
  146. <?php
  147. }
  148. ?>
  #7 (permalink)  
Antiguo 02/04/2014, 11:25
fiu
 
Fecha de Ingreso: diciembre-2006
Ubicación: Barcelona
Mensajes: 128
Antigüedad: 17 años, 4 meses
Puntos: 8
Respuesta: No me llegan todos los datos de mi formulario php

Hola, el dólar en el asunto te sale por que está puesto después de $prefijo:
Código PHP:
Ver original
  1. mail("$email", "$prefijo $", "$contenido", "From: $f_name <$f_mail>");

y he probado el formulario, y no hay error al enviar los datos, los datos llegan y luego se vuelven a colocar en los campos del formulario, lo que pasa es que no haces uso de ellos (de edad y población).

Si no los muestras, los guardas en ninguna variable ni los envías, no los verás en ningún sitio excepto los inputs del form.
  #8 (permalink)  
Antiguo 04/04/2014, 02:20
 
Fecha de Ingreso: marzo-2014
Mensajes: 11
Antigüedad: 10 años, 1 mes
Puntos: 0
Pregunta Respuesta: No me llegan todos los datos de mi formulario php

Cita:
Iniciado por fiu Ver Mensaje
Hola, el dólar en el asunto te sale por que está puesto después de $prefijo:
Código PHP:
Ver original
  1. mail("$email", "$prefijo $", "$contenido", "From: $f_name <$f_mail>");

y he probado el formulario, y no hay error al enviar los datos, los datos llegan y luego se vuelven a colocar en los campos del formulario, lo que pasa es que no haces uso de ellos (de edad y población).

Si no los muestras, los guardas en ninguna variable ni los envías, no los verás en ningún sitio excepto los inputs del form.
Genial Fiu, el dólar en el asunto solucionado. Efectivamente no hay error en la recepción de datos, como ya comenté, excepto que edad y población, como bien dices, no aparecen en el correo que recibo.

¿Cómo puedo hacer para recibirlo? Y lo más importante para mi pobre cerebro novato, ¿dónde tendría que colocarlo exactamente?

Gracias por vuestra valiosa ayuda.
  #9 (permalink)  
Antiguo 04/04/2014, 11:36
fiu
 
Fecha de Ingreso: diciembre-2006
Ubicación: Barcelona
Mensajes: 128
Antigüedad: 17 años, 4 meses
Puntos: 8
Respuesta: No me llegan todos los datos de mi formulario php

La funcion mail() es muy sencilla, échale un vistazo.

el tercer valor es el contenido del email que, no por casuallidad, es tu variable $contenido:

Código PHP:
Ver original
  1. $contenido = "$f_message
  2. $informacion
  3. ";

ahí puedes añadirle lo que quieras, el $f_Edad, texto lo que sea. Pero eso es muy básico

Etiquetas: formulario, llegan
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 12:49.