Diferencia entre revisiones de «Usuario:ManuelRomero/ProgramacionWeb/Inaem2021/formularios/resumen»
De WikiEducator
(Página creada con «{{:Usuario:ManuelRomero/ProgramacionWeb/Inaem2021/formularios/nav}}») |
|||
| Línea 1: | Línea 1: | ||
{{:Usuario:ManuelRomero/ProgramacionWeb/Inaem2021/formularios/nav}} | {{:Usuario:ManuelRomero/ProgramacionWeb/Inaem2021/formularios/nav}} | ||
| + | ===Crear un formulario típico=== | ||
| + | <source lang=html5> | ||
| + | ..... | ||
| + | <form action="index.php" method="POST"> | ||
| + | Nombre | ||
| + | <input type=text name = 'nombre'> | ||
| + | Apellido | ||
| + | <input type=text name = 'apellido'> | ||
| + | <br /> | ||
| + | <input type=submit value='enviar' name = 'submit'> | ||
| + | </form> | ||
| + | ---- | ||
| + | </source> | ||
| + | |||
| + | ===Leer datos en el servidor=== | ||
| + | <source lang=php> | ||
| + | <?php | ||
| + | $nombre = $_POST['nombre']; | ||
| + | $apellido = $_POST['apellido']; | ||
| + | ?> | ||
| + | </source> | ||
| + | |||
| + | ===Leer sólo si hemos presionado el submit=== | ||
| + | <source lang=php> | ||
| + | <?php | ||
| + | if (isset$_POST['submit')){ | ||
| + | $nombre = $_POST['nombre']; | ||
| + | $apellido = $_POST['apellido']; | ||
| + | $msj = "Has insertado los valores nombre =$nombre y apellido = $apellido"; | ||
| + | }else{ | ||
| + | $msj = "Se carga la página sin haber hecho click en el submit"; | ||
| + | } | ||
| + | ?> | ||
| + | <!doctype html> | ||
| + | <html lang="en"> | ||
| + | <head> | ||
| + | <meta charset="UTF-8"> | ||
| + | <title>Document</title> | ||
| + | </head> | ||
| + | <body> | ||
| + | <?php echo "Valor de msj generado desde php $msj; ?> | ||
| + | </body> | ||
| + | </html> | ||
| + | </source> | ||
| + | ===Leer diferentes input=== | ||
| + | *Todos se leen a partir de su name | ||
| + | *En el caso de ser una collección de elementos (p.e. checkbox), leo una colección de elementos | ||
| + | *Esto es un array que ya estudaremos | ||
| + | <source lang=php> | ||
| + | |||
| + | |||
| + | </source> | ||
Última revisión de 17:17 1 ene 2022
Contenido
Crear un formulario típico
..... <form action="index.php" method="POST"> Nombre <input type=text name = 'nombre'> Apellido <input type=text name = 'apellido'> <br /> <input type=submit value='enviar' name = 'submit'> </form> ----
Leer datos en el servidor
<?php $nombre = $_POST['nombre']; $apellido = $_POST['apellido']; ?>
Leer sólo si hemos presionado el submit
<?php if (isset$_POST['submit')){ $nombre = $_POST['nombre']; $apellido = $_POST['apellido']; $msj = "Has insertado los valores nombre =$nombre y apellido = $apellido"; }else{ $msj = "Se carga la página sin haber hecho click en el submit"; } ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <?php echo "Valor de msj generado desde php $msj; ?> </body> </html>
Leer diferentes input
- Todos se leen a partir de su name
- En el caso de ser una collección de elementos (p.e. checkbox), leo una colección de elementos
- Esto es un array que ya estudaremos
