Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/07/2012, 06:45
Avatar de patilanz
patilanz
 
Fecha de Ingreso: enero-2012
Mensajes: 880
Antigüedad: 12 años, 3 meses
Puntos: 29
Pregunta Problema al validar unos campos

Hola hize un programa que antes me funcionaba pero perdi el archivo y luego la hize de nuevo pero no consegui hacer la igual y me sale que hay error en la linea 39
Me podeis ayudar a resolverlo pls

Código PHP:
Ver original
  1. <?php
  2. //Primero vamos a crear una funcion para los errores
  3. function errores() {
  4.     $errores = array();
  5.     //Comprobamos el nombre:
  6.     if(strlen($GLOBALS[$value['nombre']]) < 2) {
  7.         $errores[0] = '<font color="#FF0000">Por favor escribe un nombre correcto!</font>';
  8.     }
  9.     if(strlen($GLOBALS[$value['nombre']]) > 10) {
  10.         $errores[1] = '<font color="#FF0000">Por favor escriba un nombre correcto!</font>';
  11.     }
  12.     //Comprobamos el email con un patron solo para emails
  13.     if(!preg_match("/^[^\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/",$GLOBALS[$value['email']])) {
  14.         $errores[2] = '<font color="#FF0000">Por favor escriba un email valido!</font>';   
  15.     }
  16.     //Comprobamos el lugar por si alguien escribe algo con 2 caracteres (Si no escribe nada no se comprobara)
  17.     if(strlen($GLOBALS[$value['lugar']]) < 2) {
  18.         $errores[3] = '<font color="#FF0000">Por favor escriba un lugar valido!</font>';
  19.     }
  20.     if(strlen($GLOBALS[$value['lugar']]) > 30) {
  21.         $errores[4] = '<font color="#FF0000">Por favor escriba un lugar valido!</font>';   
  22.     }  
  23.     //Validamos los comentarios
  24.     if(strlen($GLOBALS[$value['comentario']]) < 10) {
  25.         $errores[5] = '<font color="#FF0000">Por favor escriba un comentario mas largo!</font>';
  26.     }
  27.     if(strlen($GLOBALS[$value['comentario']]) > 1000) {
  28.         $errores[6] = '<font color="#FF0000">Por favor escriba un comentario mas largo!</font>'; //En este caso seria spam!
  29.     }
  30.     return $errores; //Aqui cogemos el array errores para usarlo posteriormente
  31. } //Terminamos la funcion
  32. $value = $_POST;
  33. if($value['oculto']) {
  34.     if(!empty($value['nombre']) && isset($value['nombre']) &&
  35.         !empty($value['email']) && isset($value['email']) &&
  36.         !empty($value['comentario']) && isset($value['comentario'])) {
  37.         //Si los errores no existen... creara y enviara el mensaje
  38.         $errores = errores();
  39.         if(!array_key_exists($errores)) {
  40.             $fecha=date("d-m-Y");
  41.             $hora=date("H:i:s");
  42.             $destino = 'Tu email';//En esta parte escribiis el email al que quereis que llegue el mensaje
  43.             $asunto = 'Comentario';
  44.             $desde = "From: ".htmlentities($value['email']);
  45.             //Creamos el mensaje
  46.             if(!empty($value['lugar']) && isset($value['lugar'])) {
  47.                 $mensaje = '
  48.             Nombre: ' + htmlentities($value['nombre']) + '\n
  49.             Email: ' + htmlentities($value['email']) + '\n
  50.             Lugar: ' + htmlentities($value['lugar']) + '\n
  51.             Comentario: ' + $value['comentario'] + '\n
  52.             Enviado: ' + $fecha + 'a las ' + $hora + '\n \n';  
  53.             } else {
  54.                 $mensaje = '
  55.             Nombre: ' + htmlentities($value['nombre']) + '\n
  56.             Email: ' + htmlentities($value['email']) + '\n
  57.             No se escribio lugar. \n
  58.             Comentario: ' + htmlentities($value['comentario']) + '\n
  59.             Enviado: ' + $fecha + 'a las ' + $hora + '\n \n';  
  60.             }
  61.             print '<p style="background-color:green; border-radius:20;">';
  62.             mail($destino, $asunto, $mensaje, $desde); //Enviamos el mensaje
  63.             print 'EL mensaje ha sido enviado!';
  64.             print '</p>';
  65.         } else { //Si existen errores...
  66.                 print '<form method="post" action="formularito.php">
  67. <table width="200" border="1" bordercolor="#0066FF">
  68.  <tr>
  69.    <td>*Nombre:</td>
  70.    <td><label for="nombre"></label>
  71.    <input type="text" name="nombre" id="nombre"></td>
  72.  </tr>
  73.  <tr>
  74.    <td>*Email:</td>
  75.    <td><label for="email"></label>
  76.      <input type="text" name="email" id="email"></td>
  77.  </tr>
  78.  <tr>
  79.    <td>Lugar:</td>
  80.    <td><label for="lugar"></label>
  81.      <input type="text" name="lugar" id="lugar"></td>
  82.  </tr>
  83.  <tr>
  84.    <td>*Comentario:</td>
  85.    <td><label for="comentario"></label>
  86.      <textarea name="comentario" id="comentario" cols="21" rows="5"></textarea></td>
  87.  </tr>
  88.  </table>
  89. <table width="200" border="0">
  90.  <tr>
  91.    <td><input type="submit" name="button" id="button" value="Enviar" style="border-radius:20px; background-color:#0CC;"></td>
  92.  </tr>
  93. </table>
  94.  
  95. <table width="500" border="0">
  96.  <tr>
  97.    <td><h3>Por favor corrige los siguientes errores: <br /><font color="#FF0000"><ul><li>';
  98.    
  99.                 print implode('</li><li>', errores());
  100.                 print '</li></ul></font>';
  101.                 print'   </td>
  102.  </tr>
  103. </table>
  104.  
  105. <p>&nbsp;</p>
  106. <input type="hidden" value="1" name="oculto" />
  107. </form>';
  108.            
  109.            
  110.         }
  111.     }else {
  112.         print '<form method="post" action="formularito.php">
  113. <table width="200" border="1" bordercolor="#0066FF">
  114.  <tr>
  115.    <td>*Nombre:</td>
  116.    <td><label for="nombre"></label>
  117.    <input type="text" name="nombre" id="nombre"></td>
  118.  </tr>
  119.  <tr>
  120.    <td>*Email:</td>
  121.    <td><label for="email"></label>
  122.      <input type="text" name="email" id="email"></td>
  123.  </tr>
  124.  <tr>
  125.    <td>Lugar:</td>
  126.    <td><label for="lugar"></label>
  127.      <input type="text" name="lugar" id="lugar"></td>
  128.  </tr>
  129.  <tr>
  130.    <td>*Comentario:</td>
  131.    <td><label for="comentario"></label>
  132.      <textarea name="comentario" id="comentario" cols="21" rows="5"></textarea></td>
  133.  </tr>
  134.  </table>
  135. <table width="317" border="0">
  136.  <tr>
  137.    <td><p>
  138.      <input type="submit" name="button" id="button" value="Enviar" style="border-radius:20px; background-color:#0CC;">
  139.    </p>
  140.      <font style="color:#FF0000"><h3>Por favor rellene los campos necesarios!</h3></font></p></td>
  141.  </tr>
  142. </table>
  143. <p>&nbsp;</p>
  144. <input type="hidden" value="1" name="oculto" />
  145. </form>';  
  146.     }  
  147. }else{
  148.     print '<form method="post" action="formularito.php">
  149. <table width="200" border="1" bordercolor="#0066FF">
  150.  <tr>
  151.    <td>*Nombre:</td>
  152.    <td><label for="nombre"></label>
  153.    <input type="text" name="nombre" id="nombre"></td>
  154.  </tr>
  155.  <tr>
  156.    <td>*Email:</td>
  157.    <td><label for="email"></label>
  158.      <input type="text" name="email" id="email"></td>
  159.  </tr>
  160.  <tr>
  161.    <td>Lugar:</td>
  162.    <td><label for="lugar"></label>
  163.      <input type="text" name="lugar" id="lugar"></td>
  164.  </tr>
  165.  <tr>
  166.    <td>*Comentario:</td>
  167.    <td><label for="comentario"></label>
  168.      <textarea name="comentario" id="comentario" cols="21" rows="5"></textarea></td>
  169.  </tr>
  170.  </table>
  171. <table width="200" border="0">
  172.  <tr>
  173.    <td><input type="submit" name="button" id="button" value="Enviar" style="border-radius:20px; background-color:#0CC;"></td>
  174.  </tr>
  175. </table>
  176. <p>&nbsp;</p>
  177. <input type="hidden" value="1" name="oculto" />
  178. </form>';  
  179. }
  180. ?>


Pls ayuden me a resolver el problema