폴더 구조
public
ㄴform.css
ㄴindex.php
templates
ㄴform.html
ㄴwelcome.html
if (!isset($_POST['firstname'])) {
include __DIR__ . '/../templates/form.html.php';
} else {
$firstName = $_POST['firstname'];
$lastName = $_POST['lastname'];
if ($firstName == 'K' && $lastName == 'G') {
$output = '환영합니다 K G 님';
} else {
$output = htmlspecialchars($firstName,ENT_QUOTES,'UTF-8').' '.
htmlspecialchars($lastName,ENT_QUOTES,'UTF-8').' 님 홈페이지 방문을 환영합니다.';
}
include __DIR__ . '/../templates/welcome.html.php';
}
index.php
<!doctype html>
<html>
<head>
<title>이름을 입력하세요</title>
<link rel="stylesheet" href="form.css" />
<meta charset="utf-8">
</head>
<body>
<form action="" method="post">
<label for="firstname">이름: </label>
<input type="text" name="firstname" id="firstname">
<label for="lastname">성: </label>
<input type="text" name="lastname" id="lastname">
<input type="submit" value="제 출">
</form>
</body>
form.html.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>폼 예제</title>
</head>
<body>
<p>
<?php echo $output; ?>
</p>
</body>
</html>
welcome.php
body {font-size: 1.2em; font-family: arial, helvetica, sans-serif}
input, label, select, textarea {float: left; width: 15em; margin-bottom: 1em; padding: 0.5em;}
label {clear: left; padding: 0; margin: 0;}
input[type="submit"] {margin-left: 15em; width: auto; padding: 0.5em 1em; clear: both; font-size: 1em;}
form {overflow: auto; clear: both; display: block;}
form.css
댓글