<?php
if (isset($_POST["submit"])) {
/* ambil nilai form */
$nama = htmlentities(strip_tags(trim($_POST["nama"])));
$email = htmlentities(strip_tags(trim($_POST["email"])));
$buku = strtolower(htmlentities(strip_tags(trim($_POST["buku"]))));
$pesan_eror = "";
$array_buku = ["html uncover", "css uncover", "php uncover"];
if (empty($nama)) {
$pesan_eror .= "Nama belum diisi <br>";
} elseif (strlen($nama) <= 5) {
$pesan_eror .= "nama harus 5 digit <br>";
}
if (empty($email)) {
$pesan_eror .= "Email belum diisi";
} elseif (strpos($email, "@") == false) {
$pesan_eror .= "Penulisan alamat email salah <br>";
}
if (empty($buku)) {
$pesan_eror .= "Buku belum diisi";
} elseif (!in_array($buku, $array_buku)) {
$pesan_eror .= "Buku tidak tersedia";
}
if ($pesan_eror == "") {
echo "<h1>Form Berhasil diproses</h1>";
echo "Nama : $nama <br>";
echo "Email : $email <br>";
echo "Buku : $buku";
die();
}
} else {
$pesan_eror = "";
$nama = "";
$buku = "";
$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>
<datalist id="list_buku">
<option value="php uncover" label="php uncover">
<option value="html uncover" label="html uncover">
<option value="css uncover" label="css uncover">
</datalist>
<?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 ?>" placeholder="nama lengkap">
</p>
<p>
<label for=""> Email : </label>
<input type="text" name="email" value="<?php echo $email ?>" placeholder="alamat email">
</p>
<p>
<label for=""> Buku : </label>
<input type="text" name="buku" list="list_buku" value="<?php echo $buku ?>" placeholder="Pilih Buku yang tersedia">
</p>
<p>
<input type="submit" name="submit" value="Proses Data" id="">
</p>
</fieldset>
</form>
</body>
</html>
Halaman
Menu
- 10 Jari
- Accessories
- Adobe
- After Effect
- Alamat
- APK
- Beli
- Biner
- BLK
- Blogger
- Bot
- Browser
- C
- Canva
- Capture
- CBT
- Cek
- Cetak
- ChatGPT
- Chrome
- Coding
- Corel
- Crack
- CSS
- Desain
- Domain
- Download
- Driver
- Ebook
- Editing Video
- Element
- Excel
- FastStone
- Fonts
- Form
- Gambar
- Gateway
- GIT
- Gmail
- HMTL
- Icon AppSheet
- IDM
- Install
- Java
- Kajian
- KI-KD
- Logo
- Media
- Ms. Excel
- Ms. Word
- Office
- Partisi
- Penting
- PHP
- Pintaar
- Portable
- Printer
- Psuedocode
- Qur'an
- Repair
- Rubik
- Setting Wifi
- Software
- Tik
- Tutorial
- VB
- VS COde
- Wali Kamar
- Web Browser
- Windows
- Winrar
Tidak ada komentar:
Posting Komentar