← Volver

Formularios y recepción de valores en PHP

Publicado el 27 de abril de 2025

Con el siguiente código podemos obtener los valores del formulario en el mismo archivo php.

<?php

if (isset($_POST["name"])) {
    echo ("nombre:" . $_POST["name"]);
}


?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <h1>Formularios</h1>

    <form action="" method="POST">
        <p>
            <input type="text" name="name" id="name" placeholder="Nombre">
        </p>

        <p>
            <input type="text" name="correo" id="correo" placeholder="Email">
        </p>

        <input type="submit" value="Enviar">

    </form>

</body>

</html>