Minggu, 31 Mei 2020

Form 1 FIle index.php

<?php
if (isset($_POST["submit"])) {
    /* ambil nilai form */
    $nama = htmlentities(strip_tags(trim($_POST["nama"])));
    $email = htmlentities(strip_tags(trim($_POST["email"])));
    $pesan_eror = "";
    if (empty($nama)) {
        $pesan_eror .= "Nama belum diisi <br>";
    }
    if (empty($email)) {
        $pesan_eror .= "Email belum diisi";
    }
    if ($pesan_eror == "") {
        echo "<h1>Form Berhasil diproses</h1>";
        echo "Nama : $nama <br>";
        echo "Email : $email";
        die();
    }
} else {
    $pesan_eror = "";
    $nama = "";
    $email = "";
}
?>
<!DOCTYPE html>
<html lang="en">

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

<body>
    <?php
    echo $pesan_eror;
    ?>
    <form action="index.php" method="POST">
        <fieldset>
            <legend align="">Latihan Form</legend>
            <p>
                <label for=""> Nama : </label>
                <input type="text" name="nama" value="<?php echo $nama ?>" id="">
            </p>
            <p>
                <label for=""> Email</label>
                <input type="text" name="email" value="<?php echo $email ?>" id="">
            </p>
            <p>
                <input type="submit" name="submit" value="Proses Data" id="">
            </p>
        </fieldset>
    </form>
</body>

</html>

Tidak ada komentar:

Posting Komentar