입력폼에서 자바스크립트를 이용하여 필수 입력사항을 검사하는 처리를 추가합니다.
1. 쪽지보내기 폼 페이지
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>쪽지보내기</title>
<link rel="stylesheet" type="text/css" href="./css/common.css">
<link rel="stylesheet" type="text/css" href="./css/message.css">
<script type="text/javascript" src="./js/message.js"></script>
</head>
<body>
<header>
<?php include "header.php";?>
</header>
<?php
if (!$userid )
{
echo("<script>
alert('로그인 후 이용해주세요!');
history.go(-1);
</script>
");
exit;
}
?>
<section>
<div id="message_box">
<h3 id="write_title">쪽지 보내기</h3>
<ul class="top_buttons">
<li><span><a href="message_box.php?mode=rv">수신 쪽지함 </a></span></li>
<li><span><a href="message_box.php?mode=send">송신 쪽지함</a></span></li>
</ul>
<form name="message_form" method="post" action="message_insert.php?send_id=<?=$userid?>">
<div id="write_msg">
<ul>
<li>
<span class="col1">보내는 사람 : </span>
<span class="col2"><?=$userid?></span>
</li>
<li>
<span class="col1">수신 아이디 : </span>
<span class="col2"><input name="rv_id" type="text"></span>
</li>
<li>
<span class="col1">제목 : </span>
<span class="col2"><input name="subject" type="text"></span>
</li>
<li id="text_area">
<span class="col1">내용 : </span>
<span class="col2">
<textarea name="content"></textarea>
</span>
</li>
</ul>
<button type="button" onclick="check_input()">보내기</button>
</div>
</form>
</div> <!-- message_box -->
</section>
<footer>
<?php include "footer.php";?>
</footer>
</body>
</html>
2. 답변 쪽지 보내기 폼 페이지
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>쪽지함>답변쪽지 보내기</title>
<link rel="stylesheet" type="text/css" href="./css/common.css">
<link rel="stylesheet" type="text/css" href="./css/message.css">
<script type="text/javascript" src="./js/message_response.js"></script>
</head>
<body>
<header>
<?php include "header.php";?>
</header>
<section>
<div id="message_box">
<h3 id="write_title">답변 쪽지 보내기</h3>
<?php
$num = $_GET["num"];
$con = mysqli_connect("localhost", "user1", "12345", "sample");
$sql = "select * from message where num=$num";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result);
$send_id = $row["send_id"];
$rv_id = $row["rv_id"];
$subject = $row["subject"];
$content = $row["content"];
$subject = "RE: ".$subject;
$content = "> ".$content;
$content = str_replace("\n", "\n>", $content);
$content = "\n\n\n-----------------------------------------------\n".$content;
$result2 = mysqli_query($con, "select name from members where id='$send_id'");
$record = mysqli_fetch_array($result2);
$send_name = $record["name"];
?>
<form name="message_form" method="post" action="message_insert.php?send_id=<?=$userid?>">
<input type="hidden" name="rv_id" value="<?=$send_id?>">
<div id="write_msg">
<ul>
<li>
<span class="col1">보내는 사람 : </span>
<span class="col2"><?=$userid?></span>
</li>
<li>
<span class="col1">수신 아이디 : </span>
<span class="col2"><?=$send_name?>(<?=$send_id?>)</span>
</li>
<li>
<span class="col1">제목 : </span>
<span class="col2"><input name="subject" type="text" value="<?=$subject?>"></span>
</li>
<li id="text_area">
<span class="col1">글 내용 : </span>
<span class="col2">
<textarea name="content"><?=$content?></textarea>
</span>
</li>
</ul>
<button type="button" onclick="check_input()">보내기</button>
</div>
</form>
</div> <!-- message_box -->
</section>
<footer>
<?php include "footer.php";?>
</footer>
</body>
</html>