Submits Info to form.php



The code used for index.php is below:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../styles.css">
    <title>Self Submitting Forms</title>
</head>
<body>

    <h1 class="lesson-h1">Submits Info to form.php</h1>

    <?php
        include('form.php');
        echo "<hr>";
        include('../show_code.php');
        show_code('index.php');
        show_code('form.php');
    ?>

</body>
</html>

The code used for form.php is below:


<?php
    if(isset($_POST['name'])){
        $name = htmlentities($_POST['name']);
        if(!empty($name)){
            echo "<p>Your name is $name</p>";
        }
    }
?>

<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
    <input type="text" name="name" id="name" placeholder="Name">
    <input type="submit" value="Submit">
</form>