Diferencia entre revisiones de «Plantilla:PHP/FormulariosConceptosGenerales»
De WikiEducator
(→Cómo leer datos de usuario) |
(→Obtener datos de un formulario) |
||
| Línea 274: | Línea 274: | ||
*Dirección de correo electrónico. | *Dirección de correo electrónico. | ||
*Estudios realizados entre ESO, BACHILLER, CICLO FORMATIVO, GRADO UNIVERSITARIO (select) | *Estudios realizados entre ESO, BACHILLER, CICLO FORMATIVO, GRADO UNIVERSITARIO (select) | ||
| + | {{Plegable|hide|Posible solución index.php| | ||
| + | <source lang=php> | ||
| + | <!DOCTYPE html> | ||
| + | <!-- | ||
| + | To change this license header, choose License Headers in Project Properties. | ||
| + | To change this template file, choose Tools | Templates | ||
| + | and open the template in the editor. | ||
| + | --> | ||
| + | <html> | ||
| + | <head> | ||
| + | <meta charset="UTF-8"> | ||
| + | <title></title> | ||
| + | </head> | ||
| + | <body> | ||
| + | <fieldset style="width:60%"> | ||
| + | <legend>Datos personales</legend> | ||
| + | <form action="datos.php" method="POST"> | ||
| + | <label for="">Nombre</label> | ||
| + | <input type="text" name="nombre" id=""> | ||
| + | <label for="">Apellido</label> | ||
| + | <input type="text" name="apellidos" id=""> | ||
| + | <br /> | ||
| + | <label for="">Direccion</label> | ||
| + | <input type="text" name="direccion" id=""> | ||
| + | <br> | ||
| + | <label for=""> | ||
| + | Fecha Nacimiento | ||
| + | </label><input type="date" name="fNac" id=""> | ||
| + | <br> | ||
| + | <label for="">Edad</label> | ||
| + | <input type="text" name="edad" id=""> | ||
| + | <br /> | ||
| + | |||
| + | <b>Idiomas</b><br /> | ||
| + | <input type="checkbox" name="idiomas[]" value="castellano" id=""> | ||
| + | <label for="">Castellano</label> | ||
| + | <br> | ||
| + | |||
| + | <input type="checkbox" name="idiomas[]" value="rumano" id=""> | ||
| + | <label for="">Rumano</label> | ||
| + | <br> | ||
| + | |||
| + | |||
| + | <input type="checkbox" name="idiomas[]" value="inglés" id=""> | ||
| + | <label for="">Inglés</label> | ||
| + | <br> | ||
| + | <input type="checkbox" name="idiomas[]" value="francés" id=""> | ||
| + | <label for="">Francés</label> | ||
| + | <br> | ||
| + | <b>Género</b><br /> | ||
| + | <input type="radio" name="genero" value="masculino" id="">Masculino<br /> | ||
| + | <input type="radio" name="genero" value="femenino" id="">Femenino<br /> | ||
| + | <input type="radio" name="genero" value="no_aporta" id="">No quiero aportar<br /> | ||
| + | |||
| + | <label for="">Dirección de correo</label> | ||
| + | <input type="email" name="email" id=""><br /><br /> | ||
| + | Estudios | ||
| + | <select name="estudios"> | ||
| + | |||
| + | |||
| + | <option value="eso">ESO</option><br /> | ||
| + | <option value="bach" >BACH</option><br /> | ||
| + | <option value="cicloFormativo">Ciclo Formativo</option><br /> | ||
| + | <option value="gradoUniversitario">Grado Universitario</option><br /> | ||
| + | </select> | ||
| + | <hr /> | ||
| + | <input type="submit" value="Enviar"> | ||
| + | |||
| + | </form> | ||
| + | </fieldset> | ||
| + | |||
| + | </body> | ||
| + | </html> | ||
| + | |||
| + | </source> | ||
| + | |||
| + | }} | ||
| + | {{Plegable|hide|Posible solución: datos.php| | ||
| + | <source lang=php> | ||
| + | <?php | ||
| + | |||
| + | /* | ||
| + | * To change this license header, choose License Headers in Project Properties. | ||
| + | * To change this template file, choose Tools | Templates | ||
| + | * and open the template in the editor. | ||
| + | */ | ||
| + | |||
| + | //Primero leemos las variables | ||
| + | |||
| + | |||
| + | $nombre = filter_input(INPUT_POST, 'nombre', FILTER_SANITIZE_STRING); | ||
| + | $apellidos = filter_input(INPUT_POST, 'apellido', FILTER_SANITIZE_STRING); | ||
| + | $edad = filter_input(INPUT_POST, 'edad', FILTER_VALIDATE_INT); | ||
| + | $direccion = filter_input(INPUT_POST, 'direccion', FILTER_SANITIZE_STRING); | ||
| + | $fNac = filter_input(INPUT_POST, 'fNac', FILTER_SANITIZE_STRING); | ||
| + | $idiomas = filter_input_array(INPUT_POST, 'idiomas[]'); | ||
| + | $genero = filter_input(INPUT_POST, 'genero'); | ||
| + | $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); | ||
| + | $estudios = filter_input(INPUT_POST, 'estudios'); | ||
| + | |||
| + | // | ||
| + | $mis_idiomas = print_r($idiomas, true); | ||
| + | |||
| + | |||
| + | //Mostramos los valores como una ficha | ||
| + | |||
| + | $texto = <<<FIN | ||
| + | <pre> | ||
| + | Nombre $nombre | ||
| + | Apellido $apellido | ||
| + | Edad $edad años | ||
| + | Dirección $direccion | ||
| + | Fecha de nacimiento $fNac | ||
| + | Sexo $genero | ||
| + | Correo electrónico $email | ||
| + | Idiomas $mis_idiomas | ||
| + | Estudiso $estudios | ||
| + | </pre> | ||
| + | |||
| + | FIN; | ||
| + | echo $texto; | ||
| + | ?> | ||
| + | </source> | ||
| + | |||
| + | }} | ||
}} | }} | ||
</div> | </div> | ||
Revisión de 19:13 26 oct 2017
- Por defecto los valores son pasados por GET
- Este método es fácil de ver pues se viauliza en el URL, apareciendo como parte de él separado por el signo interrogación con parejas Variable valor

