Ver Mensaje Individual
  #3 (permalink)  
Antiguo 11/05/2010, 15:55
Avatar de elratonperez
elratonperez
 
Fecha de Ingreso: octubre-2004
Ubicación: La Ciudad Imperial
Mensajes: 332
Antigüedad: 19 años, 6 meses
Puntos: 0
Pregunta Respuesta: Enviar formulario con fecha igual o inferior a la del servidor

Hola Adler, gracias por contestar.

He intentado probar el código que me has indicado, pero no doy con ello. Perdona mi ignorancia, pero realmente es que no sé dónde ponerlo exactamente para que funcione. Bueno, en realidad sí que he conseguido que no se guarden los datos del formulario si se sobrepasa la fecha límite, pero el mensaje de "Límite pasado" se carga desde el inicio con el resto de la página... vamos, una chapuza que no vale.

Pongo el código de un formulario de ejemplo por si alguien me puede echar una mano. Es muy simple: nombre, apellidos y el botón Enviar. Lo he realizado con Dreamweaver.

Código PHP:
Ver original
  1. <?php require_once('Connections/basedatos.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38.  
  39. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "formulario1")) {
  40.   $insertSQL = sprintf("INSERT INTO bdprueba (nombre, apellido1, apellido2) VALUES (%s, %s, %s)",
  41.                        GetSQLValueString($_POST['nombre'], "text"),
  42.                        GetSQLValueString($_POST['apellido1'], "text"),
  43.                        GetSQLValueString($_POST['apellido2'], "text"));
  44.  
  45.   mysql_select_db($database_basedatos, $basedatos);
  46.   $Result1 = mysql_query($insertSQL, $basedatos) or die(mysql_error());
  47.  
  48.   $insertGoTo = "inicio.php";
  49.   if (isset($_SERVER['QUERY_STRING'])) {
  50.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  51.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  52.   }
  53.   header(sprintf("Location: %s", $insertGoTo));
  54. }
  55. ?>
  56. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  57. <html xmlns="http://www.w3.org/1999/xhtml">
  58. <head>
  59. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  60. <title>prueba2</title>
  61. </head>
  62.  
  63. <body>
  64. <form id="formulario1" name="formulario1" method="POST" action="<?php echo $editFormAction; ?>">
  65.   <p>
  66.     <label>Nombre
  67.       <input type="text" name="nombre" id="nombre" />
  68.     </label>
  69.   </p>
  70.   <p>
  71.     <label>Apellido 1
  72.       <input type="text" name="apellido1" id="apellido1" />
  73.     </label>
  74.   </p>
  75.   <p>
  76.     <label>Apellido 2
  77.       <input type="text" name="apellido2" id="apellido2" />
  78.     </label>
  79.   </p>
  80.   <p>
  81.     <label>
  82.       <input type="submit" name="enviar" id="enviar" value="Enviar" />
  83.     </label>
  84.   </p>
  85.   <input type="hidden" name="MM_insert" value="formulario1" />
  86. </form>
  87. </body>
  88. </html>

Saludos.