Diferencia entre revisiones de «Usuario:ManuelRomero/ProgramacionWeb/Inaem2019/formularios/resumen»

De WikiEducator
Saltar a: navegación, buscar
(Leer datos en el servidor)
(Leer sólo si hemos presionado el submit)
Línea 22: Línea 22:
  
 
===Leer sólo si hemos presionado el submit===
 
===Leer sólo si hemos presionado el submit===
 
+
<source lang=php>
 
<?php
 
<?php
 
if (isset$_POST['submit')){
 
if (isset$_POST['submit')){
Línea 32: Línea 32:
 
}
 
}
 
?>
 
?>
<!>
+
<!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>

Revisión de 02:03 12 feb 2019

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>