* @copyright 2010 Bartolomé Sintes Marco * @license http://www.gnu.org/licenses/agpl.txt AGPL 3 or later * @version 2010-03-23 * @link https://www.mclibre.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ // Función de recogida de datos function recoge($key, $type = "") { if (!is_string($key) && !is_int($key) || $key == "") { trigger_error("Function recoge(): Argument #1 (\$key) must be a non-empty string or an integer", E_USER_ERROR); } elseif ($type !== "" && $type !== []) { trigger_error("Function recoge(): Argument #2 (\$type) is optional, but if provided, it must be an empty array or an empty string", E_USER_ERROR); } $tmp = $type; if (isset($_REQUEST[$key])) { if (!is_array($_REQUEST[$key]) && !is_array($type)) { $tmp = trim(htmlspecialchars($_REQUEST[$key])); } elseif (is_array($_REQUEST[$key]) && is_array($type)) { $tmp = $_REQUEST[$key]; array_walk_recursive($tmp, function (&$value) { $value = trim(htmlspecialchars($value)); }); } } return $tmp; } function cabecera($texto) { print "\n"; print "\n"; print "\n"; print " \n"; print " \n"; print " $texto. Validación.\n"; print " Ejercicios. PHP. Bartolomé Sintes Marco. www.mclibre.org\n"; print " \n"; print " \n"; print " \n"; print "\n"; print "\n"; print "\n"; print "

$texto

\n"; print "\n"; } define("FORM_METHOD", "get"); define("TAM_NOMBRE", 40); define("TAM_TELEFONO", 9); define("TAM_CORREO", 40); $nombre = recoge("nombre"); $telefono = recoge("telefono"); $correo = recoge("correo"); if (isset($_REQUEST["enviar"])) { cabecera("Formulario y resultado en un único archivo (Resultado)"); print "

Se han recibido los datos siguientes:

\n"; print "\n"; print "

Nombre:$nombre

\n"; print "\n"; print "

Teléfono:$telefono

\n"; print "\n"; print "

Correo:$correo

\n"; print "\n"; print "

Volver al formulario

\n"; } else { cabecera("Formulario y resultado en un único archivo (Formulario)"); print "

Escriba los datos siguientes:

\n"; print "\n"; print "
\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
Nombre:
Teléfono:
Correo:
\n"; print "\n"; print "

\n"; print "
\n"; } ?>