에디터 문의드립니다.
본문
<?php
include_once('../common.php');
// 페이지 제목 설정
$g5['title'] = '후기 작성';
// 설정 불러오기
$config = sql_fetch("SELECT * FROM g5_review_config LIMIT 1");
// 권한 체크
if (!$is_member || $member['mb_level'] < $config['cf_write_level']) {
alert('작성 권한이 없습니다.');
}
// 수정 모드
$rv_id = isset($_GET['rv_id']) ? (int)$_GET['rv_id'] : 0;
$w = '';
$review = array();
if ($rv_id) {
$review = sql_fetch("SELECT * FROM g5_review WHERE rv_id = '$rv_id'");
if (!$review) {
alert('존재하지 않는 후기입니다.');
}
// 작성자 본인이거나 관리자인 경우만 수정 가능
if ($review['mb_id'] != $member['mb_id'] && !$is_admin) {
alert('수정 권한이 없습니다.');
}
$w = 'u';
$g5['title'] = '후기 수정';
}
// 헤더 include
include_once('./header.php');
?><div class="rvw-container">
<!-- 페이지 헤더 -->
<div class="rvw-header">
<a href="review.php" class="rvw-back-btn">
<i class="bi bi-chevron-left"></i>
</a>
<h2><i class="bi bi-pencil-square"></i> 후기 <?php echo $w ? '수정' : '작성'; ?></h2>
</div>
<form id="reviewForm" name="fwrite" action="<?php echo G5_URL; ?>/game/review_update.php" method="post" enctype="multipart/form-data" class="rvw-form" onsubmit="return validateForm();">
<input type="hidden" name="w" value="<?php echo $w; ?>">
<input type="hidden" name="rv_id" value="<?php echo $rv_id; ?>">
<input type="hidden" name="token" value="<?php echo get_session('ss_token'); ?>">
<div class="rvw-group">
<label>사진 업로드 <?php echo !$w ? '<span style="color: #e91e63;">*</span>' : ''; ?></label>
<div class="rvw-photo-upload" onclick="document.getElementById('rv_photo').click();">
<input type="file" name="rv_photo" id="rv_photo" accept="image/jpeg,image/jpg,image/png,image/gif" onchange="previewImage(this);">
<?php if ($w && $review['rv_photo']) { ?>
<img src="<?php echo G5_DATA_URL.'/review/'.$review['rv_photo']; ?>" class="rvw-photo-preview" id="preview">
<?php } else { ?>
<div id="preview-text"><i class="bi bi-camera" style="font-size: 40px; color: #999;"></i><br>클릭하여 사진 업로드</div>
<img src="" class="rvw-photo-preview" id="preview" style="display: none;">
<?php } ?>
</div>
<div class="error-msg" id="photo-error">사진을 업로드해주세요.</div>
</div>
<div class="rvw-group">
<label>이름 <span style="color: #e91e63;">*</span></label>
<input type="text" name="rv_name" id="rv_name" class="rvw-control" required value="<?php echo isset($review['rv_name']) ? $review['rv_name'] : $member['mb_nick']; ?>" placeholder="표시될 이름">
<div class="error-msg" id="name-error">이름을 입력해주세요.</div>
</div>
<div class="rvw-group">
<label>후기 내용 <span style="color: #e91e63;">*</span></label>
<textarea name="rv_content" id="rv_content" class="rvw-control" rows="5" required placeholder="후기 내용을 입력해주세요..."><?php echo isset($review['rv_content']) ? $review['rv_content'] : ''; ?></textarea>
<div class="error-msg" id="content-error">후기 내용을 입력해주세요.</div>
</div>
<div class="rvw-group">
<label>평점 <span style="color: #e91e63;">*</span></label>
<div class="rvw-star-rating">
<?php
$current_star = isset($review['rv_star']) ? $review['rv_star'] : 5;
for ($i = 5; $i >= 1; $i--) {
$checked = ($i == $current_star) ? 'checked' : '';
?>
<input type="radio" name="rv_star" id="star<?php echo $i; ?>" value="<?php echo $i; ?>" <?php echo $checked; ?>>
<label for="star<?php echo $i; ?>">★</label>
<?php } ?>
</div>
</div>
<div class="rvw-submit-btns">
<button type="submit" class="rvw-btn rvw-btn-primary" id="submitBtn">
<i class="bi bi-check-lg"></i> <?php echo $w ? '수정' : '작성'; ?>완료
</button>
<button type="button" class="rvw-btn rvw-btn-secondary" onclick="if(confirm('작성을 취소하시겠습니까?')) history.back();">
<i class="bi bi-x-lg"></i> 취소
</button>
</div>
</form>
</div>
<!-- 로딩 오버레이 -->
<div class="loading-overlay" id="loadingOverlay">
<div class="loading-spinner"></div>
</div>
<!-- 하단 퀵메뉴 include -->
<?php include_once('./menu.php'); ?>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
// 폼 유효성 검사
function validateForm() {
var isValid = true;
var w = '<?php echo $w; ?>';
// 모든 에러 메시지 초기화
document.querySelectorAll('.error-msg').forEach(function(el) {
el.style.display = 'none';
});
// 사진 체크 (신규 작성시만)
if (w == '' && !document.getElementById('rv_photo').files.length && !document.getElementById('preview').src) {
document.getElementById('photo-error').style.display = 'block';
isValid = false;
}
// 이름 체크
var name = document.getElementById('rv_name').value.trim();
if (!name) {
document.getElementById('name-error').style.display = 'block';
isValid = false;
}
// 후기 내용 체크
var content = document.getElementById('rv_content').value.trim();
if (!content) {
document.getElementById('content-error').style.display = 'block';
isValid = false;
}
if (isValid) {
// 로딩 표시
document.getElementById('loadingOverlay').style.display = 'flex';
document.getElementById('submitBtn').disabled = true;
// 디버깅용 로그
console.log('Form is being submitted');
console.log('Action URL:', document.getElementById('reviewForm').action);
console.log('Method:', document.getElementById('reviewForm').method);
return true;
}
return false;
}
// 이미지 미리보기
function previewImage(input) {
if (input.files && input.files[0]) {
// 파일 크기 체크 (5MB)
if (input.files[0].size > 30 * 1024 * 1024) {
alert('파일 크기는 30MB 이하만 가능합니다.');
input.value = '';
return;
}
// 파일 형식 체크
var allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'];
if (!allowedTypes.includes(input.files[0].type)) {
alert('JPG, PNG, GIF 형식의 이미지만 업로드 가능합니다.');
input.value = '';
return;
}
var reader = new FileReader();
reader.onload = function(e) {
document.getElementById('preview').src = e.target.result;
document.getElementById('preview').style.display = 'block';
var previewText = document.getElementById('preview-text');
if (previewText) previewText.style.display = 'none';
document.getElementById('photo-error').style.display = 'none';
}
reader.readAsDataURL(input.files[0]);
}
}
// 별점 처리
document.addEventListener('DOMContentLoaded', function() {
// 별점 초기화
var checkedStar = document.querySelector('.rvw-star-rating input[type="radio"]:checked');
if (checkedStar) {
var checkedIndex = parseInt(checkedStar.value);
document.querySelectorAll('.rvw-star-rating label').forEach(function(label, index) {
if (index >= (5 - checkedIndex)) {
label.style.color = '#ffd700';
}
});
}
// 별점 클릭 이벤트
document.querySelectorAll('.rvw-star-rating label').forEach(function(label) {
label.addEventListener('click', function() {
var stars = document.querySelectorAll('.rvw-star-rating label');
var clickedIndex = Array.from(stars).indexOf(this);
stars.forEach(function(star, index) {
if (index >= clickedIndex) {
star.style.color = '#ffd700';
} else {
star.style.color = '#ddd';
}
});
});
});
// 폼 제출 디버깅
document.getElementById('reviewForm').addEventListener('submit', function(e) {
console.log('Form submit event triggered');
if (!validateForm()) {
e.preventDefault();
console.log('Form validation failed');
}
});
});
// 입력 필드 변경시 에러 메시지 숨기기
document.querySelectorAll('.rvw-control').forEach(function(input) {
input.addEventListener('input', function() {
var errorId = this.id.replace('rv_', '') + '-error';
var errorEl = document.getElementById(errorId);
if (errorEl) {
errorEl.style.display = 'none';
}
});
});
</script>
</body>
</html>
editor 기능은 들어 있는거 같은데 에디터가 나오지 않습니다.
<div class="rvw-group">
<label>후기 내용 <span style="color: #e91e63;">*</span></label>
<textarea name="rv_content" id="rv_content" class="rvw-control" rows="5" required placeholder="후기 내용을 입력해주세요..."><?php echo isset($review['rv_content']) ? $review['rv_content'] : ''; ?></textarea>
<div class="error-msg" id="content-error">후기 내용을 입력해주세요.</div>
</div>
이부분에서 에디터를 출력해줘야 하는데 출력이 안됩니다 .방법좀 알려주세요