회원가입 필드의 값에 따라 게시판 분리하기
본문
사전상담을 통해 회원유형을 정해주고,
G5로 만든 사이트에서 정해진 회원유형에 따라 온라인 회원가입을 받고 있습니다.
회원가입시에 가입폼에
mb_10 필드에 회원유형을 선택하게 추가했고요.
회원들이 로그인 후 자신의 유형에 맞춰 상담을 위한 사전 설문지를 작성할 수 있습니다.
회원유형 (mb_10) 이 type1 , type2, type3 로 나누어져 있고요.
설문지는 게시판을 커스터마이징해서 [bo_table] "form01 , form2, form3 으로
각각의 폼게시판이 만들어져 있습니다.
회원로그인후 설문신청서 작성 페이지에서
[type1] , [type2], [type3] 버튼을 만든후
mb_10 이 type1 이면 bo_table=form01 게시판
mb_10 이 type2 이면 bo_table=form02 게시판
mb_10 이 type3 이면 bo_table=form02 게시판
으로 가는 버튼만 클릭이 가능하고, 나머지 버튼은 "회원유형을 확인해주세요." 라는
alert 창이 뜨게 할 수 있을까요?
답변 2
mb_10 필드 값을 기반으로 특정 게시판으로 이동하는 버튼을 제어하는 기능을 추가하려면,
JavaScript와 PHP를 조합하여 구현하는 것이 적절합니다.
- 로그인한 사용자의 mb_10 값을 가져와서,
해당 값에 맞는 버튼만 활성화하고 나머지는 alert("회원유형을 확인해주세요.")을 띄움.
- 세션을 이용하여 로그인한 사용자의 mb_10 값을 가져와 JavaScript에 전달.
- onclick 이벤트를 통해 bo_table을 설정하고, 조건이 맞는 경우만 게시판으로 이동.
※ 설문 조사 선택 페이지 예시 ※
<?php
include_once('./_common.php');
// 로그인 확인
if (!$is_member) {
alert("로그인이 필요합니다.", G5_BBS_URL.'/login.php');
exit;
}
// 로그인한 사용자의 mb_10 값 가져오기
$member_type = isset($member['mb_10']) ? $member['mb_10'] : "";
?>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>설문 조사 선택</title>
<script>
document.addEventListener("DOMContentLoaded", function () {
let memberType = "<?= $member_type ?>"; // PHP에서 전달받은 회원 유형 값
function checkAccess(type, board) {
if (memberType === type) {
location.href = "/bbs/board.php?bo_table=" + board;
} else {
alert("회원유형을 확인해주세요.");
}
}
document.getElementById("btn_type1").addEventListener("click", function () {
checkAccess("type1", "form01");
});
document.getElementById("btn_type2").addEventListener("click", function () {
checkAccess("type2", "form02");
});
document.getElementById("btn_type3").addEventListener("click", function () {
checkAccess("type3", "form02"); // 기존 "form03" -> "form02"로 수정
});
});
</script>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
.container {
width: 400px;
margin: 0 auto;
}
.btn {
display: block;
width: 100%;
padding: 10px;
margin: 10px 0;
font-size: 16px;
cursor: pointer;
border: none;
border-radius: 5px;
}
.btn-type1 { background-color: #3498db; color: white; }
.btn-type2 { background-color: #2ecc71; color: white; }
.btn-type3 { background-color: #e74c3c; color: white; }
</style>
</head>
<body>
<div class="container">
<h2>설문 조사 선택</h2>
<p>회원님의 유형에 맞는 설문지를 선택하세요.</p>
<button id="btn_type1" class="btn btn-type1">Type1 설문</button>
<button id="btn_type2" class="btn btn-type2">Type2 설문</button>
<button id="btn_type3" class="btn btn-type3">Type3 설문</button>
</div>
</body>
</html>
<?php if($member['mb_10'] == 'type1') { ?>
<a href="<?php echo G5_BBS_URL; ?>/board.php?bo_table=form01">상담게시판</a>
<?php } else if($member['mb_10'] == 'type2') { ?>
<a href="<?php echo G5_BBS_URL; ?>/board.php?bo_table=form02">상담게시판</a>
<?php } else if($member['mb_10'] == 'type3') { ?>
<a href="<?php echo G5_BBS_URL; ?>/board.php?bo_table=form03">상담게시판</a>
<?php } else { ?>
<a href="void(0);" onclick="alert('회원유형을 확인해주세요.');location.href='<?php echo G5_BBS_URL; ?>/login.php?&url=<?php echo urlencode(G5_URL.'/coupon');?>';return false;">
<?php } ?>
이렇게 하면 됩니다.
필요한 부분은 수정하거나 하세요
G5_URL.'/coupon' 이 부분은 짧은 주소 입니다.,
참고하세요