Aliyya_Putri_Setiyomadani/form-testing/apps/formEmail.php
2024-12-31 11:09:29 +07:00

74 lines
2.3 KiB
PHP

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Email</title>
<style>
.error {
color: red;
}
</style>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body class="container-md my-3">
<?php
//Nilai variabel error
if (isset($_GET['error'])) {
$error = $_GET['error'];
} else {
$error = "";
}
//Pesan kesalahan
$pesan = "";
if ($error == "variable_undefined") {
$pesan = "Sorry, you must access this page from formEmail.php";
} elseif ($error == "empty_name") {
$pesan = "Sorry, name field required";
} elseif ($error == "invalid_name") {
$pesan = "Sorry, name must contains letter";
} elseif ($error == "empty_email") {
$pesan = "Sorry, email field required";
}
if ($error == "invalid_email") {
$pesan = "Sorry, invalid email";
}
//Isian form jika terjadi kesalahan
if (isset($_GET['yourname']) && isset($_GET['youremail'])) {
$name = $_GET['yourname'];
$email = $_GET['youremail'];
} else {
$name = "";
$email = "";
}
?>
<?php if (!empty($pesan)) : ?>
<div class="alert alert-danger error">
<?php echo $pesan; ?>
</div>
<?php endif; ?>
<form action="prosesFormEmail.php" method="get">
<div class="mb-3">
<label for="name" class="form-label">Your Name:</label>
<input type="text" class="form-control" id="name" name="yourname" value="<?php echo $name; ?>">
</div>
<div class="mb-3">
<label for="email" class="form-label">Your Email:</label>
<input type="email" class="form-control" name="youremail" id="email" value="<?php echo $email; ?>">
</div>
<input type="submit" class="btn btn-primary" name="submit" value="Submit">
</form>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</body>
</html>