댓글 여분필드 수정시 값 불러오기 실패
본문
안녕하세요.
댓글에 여분필드를 사용하고 있는데,
댓글 쓰기/뷰는 문제가 없으나, 수정하기를 누르면 기존값이 input 칸으로 넘어오지 않고 초기화 빈칸상태가 됩니다..
(왜인지 wr_1값 하나는 넘어옵니다;;)
무엇이 문제인지 코드확인 한번 부탁드립니다ㅜ
[view_comment.skn.php 페이지]
<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
?>
<script type="text/javascript">
// 글자수 제한
var char_min = parseInt(<?=$comment_min?>); // 최소
var char_max = parseInt(<?=$comment_max?>); // 최대
</script>
<? if ($cwin==1) { ?>
<table width=100% cellpadding="10" align="center">
<tr><td>
<? } ?>
<!-- 코멘트 리스트 -->
<? if(!$is_comment_write) {
$list_style = 'margin-bottom:10px;';
}
?>
<div id="commentContents" style="clear:both;<?=$list_style?>">
<?
for ($i=0; $i<count($list); $i++) {
$comment_id = $list[$i][wr_id];
?>
<div class="info">
<a name="c_<?=$comment_id?>"></a>
<div class="topinfo">
<div style="float:left; margin:2px 0 0 2px;">
<? for ($k=0; $k<strlen($list[$i][wr_comment_reply]); $k++) echo "<span><img src='$board_skin_path/img/co_icon_re.gif' align='absmiddle'></span>"; ?>
<span><?=$list[$i][name]?></span>
span style="color:#B2B2B2; font-size:11px;"><?=date("Y-m-d", strtotime($list[$i][datetime]))?></span>
<? if ($is_admin == 'super' || $is_auth) { if ($is_ip_view) { echo " <span style=\"color:#B2B2B2; font-size:11px;\">(IP:{$list[$i][ip]})</span>"; } } ?>
</div>
<div style="float:right; margin-top:2px;">
<!--? if ($list[$i][is_reply]) { echo "<a href=\"javascript:comment_box('{$comment_id}', 'c');\"><img src='$board_skin_path/img/co_btn_reply.gif' border=0 align=absmiddle alt='답변'></a> "; } ?-->
<? if ($list[$i][is_edit]) { echo "<a href=\"javascript:comment_box('{$comment_id}', 'cu');\">수정</a> "; } ?>
<? if ($list[$i][is_del]) { echo "<a href=\"javascript:comment_delete('{$list[$i][del_link]}&flag=admin');\">삭제</a> "; } ?>
</div>
</div>
<!-- 코멘트 출력 -->
<div class="cmt_cnt">
<table width=100% cellpadding="10" align="center">
<tr>
<th>횟수</th><td><?php echo str_pad($i + 1, 2, '0', STR_PAD_LEFT) ?>회</td>
</tr>
<tr>
<th>여분1</th><td><?php echo $list[$i]['wr_1']; ?></td>
<th>이름</th><td><?php echo $list[$i]['wr_name']; ?></td>
</tr>
<tr>
<th>여분3</th><td><?php echo $list[$i]['wr_3']; ?></td>
<th>여분4</th><td><?php echo $list[$i]['wr_4']; ?></td>
</tr>
<tr>
<th>여분5,6</th><td><?php echo $list[$i]['wr_5']; ?> (<?php echo $list[$i]['wr_6']; ?>시)</td>
</tr>
<tr>
<th>여분7</th><td><?php echo $list[$i]['wr_7']; ?></td>
</tr>
<tr>
<th>여분8</th><td><?php echo $list[$i]['wr_8']; ?></td>
</tr>
<tr>
<th>메모</th>
<td>
<? for ($k=0; $k<strlen($list[$i][wr_comment_reply]); $k++) echo " "; ?>
<?
$str = $list[$i][content];
if (strstr($list[$i][wr_option], "secret")) //비밀글일때
$str = "<span class='small' style='color:#ff6600;'>* $str</span>";
$str = preg_replace("/\[\<a\s.*href\=\"(http|https|ftp|mms)\:\/\/([^[:space:]]+)\.(mp3|wma|wmv|asf|asx|mpg|mpeg)\".*\<\/a\>\]/i", "<script>doc_write(obj_movie('$1://$2.$3'));</script>", $str);
// FLASH XSS 공격에 의해 주석 처리 - 110406
//$str = preg_replace("/\[\<a\s.*href\=\"(http|https|ftp)\:\/\/([^[:space:]]+)\.(swf)\".*\<\/a\>\]/i", "<script>doc_write(flash_movie('$1://$2.$3'));</script>", $str);
$str = preg_replace("/\[\<a\s*href\=\"(http|https|ftp)\:\/\/([^[:space:]]+)\.(gif|png|jpg|jpeg|bmp)\"\s*[^\>]*\>[^\s]*\<\/a\>\]/i", "<img src='$1://$2.$3' id='target_resize_image[]' onclick='image_window(this);' border='0'>", $str);
echo $str;
?>
</td>
</tr>
<tr>
<th>여분9,10</th><td><?php echo $list[$i]['wr_9']; ?> <?php echo $list[$i]['wr_10']; ?> <?php echo $list[$i]['wr_2']; ?> 시</td>
</tr>
</table>
</div>
<? if ($list[$i][trackback]) { echo "<p>".$list[$i][trackback]."</p>"; } ?>
<span id='edit_<?=$comment_id?>' style='display:none;'></span><!-- 수정 -->
<span id='reply_<?=$comment_id?>' style='display:none;'></span><!-- 답변 -->
<input type=hidden id='secret_comment_<?=$comment_id?>' value="<?=strstr($list[$i][wr_option],"secret")?>">
<input type="hidden" value="<?php echo $list[$i]['wr_1'] ?>" id="save_comment_wr1_<?php echo $comment_id ?>">
<input type="hidden" value="<?php echo $list[$i]['wr_2'] ?>" id="save_comment_wr2_<?php echo $comment_id ?>">
<input type="hidden" value="<?php echo $list[$i]['wr_3'] ?>" id="save_comment_wr3_<?php echo $comment_id ?>">
<input type="hidden" value="<?php echo $list[$i]['wr_4'] ?>" id="save_comment_wr4_<?php echo $comment_id ?>">
<input type="hidden" value="<?php echo $list[$i]['wr_5'] ?>" id="save_comment_wr5_<?php echo $comment_id ?>">
<input type="hidden" value="<?php echo $list[$i]['wr_6'] ?>" id="save_comment_wr6_<?php echo $comment_id ?>">
<input type="hidden" value="<?php echo $list[$i]['wr_7'] ?>" id="save_comment_wr7_<?php echo $comment_id ?>">
<input type="hidden" value="<?php echo $list[$i]['wr_8'] ?>" id="save_comment_wr8_<?php echo $comment_id ?>">
<input type="hidden" value="<?php echo $list[$i]['wr_9'] ?>" id="save_comment_wr9_<?php echo $comment_id ?>">
<input type="hidden" value="<?php echo $list[$i]['wr_10'] ?>" id="save_comment_wr10_<?php echo $comment_id ?>">
<textarea id='save_comment_<?=$comment_id?>' style='display:none;'><?=get_text($list[$i][content1], 0)?></textarea>
</div>
<? } ?>
</div>
<!-- 코멘트 리스트 -->
<? if ($is_comment_write) { ?>
<!-- 코멘트 입력 -->
<div id=comment_write style="display:none;">
<table width=100% border=0 cellpadding=1 cellspacing=0 bgcolor="#dddddd"><tr><td>
<form name="fviewcomment" method="post" action="./write_comment_update.php" onsubmit="return fviewcomment_submit(this);" autocomplete="off" style="margin:0px;">
<input type=hidden name=w id=w value='c'>
<input type=hidden name=bo_table value='<?=$bo_table?>'>
<input type=hidden name=wr_id value='<?=$wr_id?>'>
<input type=hidden name=comment_id id='comment_id' value=''>
<input type=hidden name=sca value='<?=$sca?>' >
<input type=hidden name=sfl value='<?=$sfl?>' >
<input type=hidden name=stx value='<?=$stx?>'>
<input type=hidden name=spt value='<?=$spt?>'>
<input type=hidden name=page value='<?=$page?>'>
<input type=hidden name=cwin value='<?=$cwin?>'>
<input type=hidden name=is_good value=''>
<table width="100%" cellpadding="0" cellspacing="0" align="center" class="cmt_write_board">
<tr>
<th scope="row">여분1</th>
<td><input type="text" name="wr_1" id="wr_1" value="<?php echo $wr_1; ?>" class="frm_input"></td>
<th scope="row">이름</th>
<td><input type="text" name="wr_name" id="wr_name" value="<?php echo $wr_name; ?>" class="frm_input"></td>
</tr>
<tr>
<th scope="row">여분3</th>
<td colspan="3">
<input type="radio" name="wr_3" value="여분3-1" <?php echo ($wr_3 == "여분3-1") ? "checked" : "";?>/>여분3-1
<input type="radio" name="wr_3" value="여분3-2" <?php echo ($wr_3 == "여분3-2") ? "checked" : "";?>/>여분3-2
</td>
</tr>
<tr>
<th scope="row">여분4</th>
<td colspan="3">
<input type="radio" name="wr_4" value="여분4-1" <?php echo ($wr_4 == "여분4-1") ? "checked" : "";?>/>대면
<input type="radio" name="wr_4" value="여분4-2" <?php echo ($wr_4 == "여분4-2") ? "checked" : "";?>/>화상
<input type="radio" name="wr_4" value="여분4-3" <?php echo ($wr_4 == "여분4-3") ? "checked" : "";?>/>전화
<input type="radio" name="wr_4" value="여분4-4" <?php echo ($wr_4 == "여분4-4") ? "checked" : "";?>/>출장
</td>
</tr>
<tr>
<th scope="row">여분5,6</th>
<td colspan="3">
<input class='inputbox dat' id="wr_5" name="wr_5" size="12" maxlength="12" minlength="10" itemname="여분5" value="<?php echo $wr_5; ?>" readonly title='옆의 달력 아이콘을 클릭하여 날짜를 입력하세요.'> <input type="text" name="wr_6" id="wr_6" value="<?php echo $wr_6; ?>" class="frm_input"> 시
</td>
</tr>
<tr>
<th scope="row">여분7</th>
<td colspan="3">
<input type="radio" name="wr_7" value="여분7-1" <?php echo ($wr_7 == "여분7-1") ? "checked" : "";?>/>여분7-1
<input type="radio" name="wr_7" value="여분7-2" <?php echo ($wr_7 == "여분7-2") ? "checked" : "";?>/>여분7-2
<input type="radio" name="wr_7" value="여분7-3" <?php echo ($wr_7 == "여분7-3") ? "checked" : "";?>/>여분7-3
</td>
<tr>
<tr>
<th scope="row">여분8</th>
<td><input type="text" name="wr_8" id="wr_8" value="<?php echo $wr_8; ?>" class="frm_input"></td>
</tr>
<tr>
<th scope="row" rowspan="2">
메모
</th>
<td colspan="3">
<span style="cursor: pointer;" onclick="textarea_decrease('wr_content', 4);"><img src="<?=$board_skin_path?>/img/up.gif" border='0' style="vertical-align:middle;"></span>
<span style="cursor: pointer;" onclick="textarea_original('wr_content', 4);"><img src="<?=$board_skin_path?>/img/start.gif" border='0' style="vertical-align:middle;"></span>
<span style="cursor: pointer;" onclick="textarea_increase('wr_content', 4);"><img src="<?=$board_skin_path?>/img/down.gif" border='0' style="vertical-align:middle;"></span>
<? if ($is_guest) { ?>
<span>이름 <INPUT type=text maxLength=20 size=10 name="wr_name" itemname="이름" required class="ed"></span>
<span>비밀번호 <INPUT type=password maxLength=20 size=10 name="wr_password" itemname="비밀번호" required class="ed"> </span>
<? } ?>
<!--span><input type=checkbox id="wr_secret" name="wr_secret" value="secret" style="vertical-align:middle;">비밀글<span style="font-size:11px;color:#808080;"></span-->
<? if ($comment_min || $comment_max) { ?><span id=char_count></span>글자<? }?></span>
<? if ($is_guest) { ?>
<span style="visibility:hidden;">
<img id='kcaptcha_image' border='0' width="75" height="35" align="absbottom" onclick="imageClick();" style="height:12px; cursor:pointer;" title="글자가 잘안보이는 경우 클릭하시면 새로운 글자가 나옵니다.">
<input title="왼쪽의 글자를 입력하세요." type="input" name="wr_key" size="10" itemname="자동등록방지" required class='ed'></span>
<? } ?>
</td>
</tr>
<tr>
<td colspan="3" style="background:#eee;">
<textarea id="wr_content" name="wr_content" rows=4 itemname="내용" required
<? if ($comment_min || $comment_max) { ?>onkeyup="check_byte('wr_content', 'char_count');"<? } ?> style='width:100%; word-break:break-all;' class="tx"><?php echo $wr_content; ?></textarea>
<? if ($comment_min || $comment_max) { ?><script type="text/javascript"> check_byte('wr_content', 'char_count'); </script><? } ?>
</td>
</tr>
<tr>
<th scope="row">여분9,10</th>
<td colspan="3">
<input class='inputbox dat' id="wr_9" name="wr_9" size="12" maxlength="12" minlength="10" itemname="여분9" value="<?php echo $wr_9; ?>" readonly title='옆의 달력 아이콘을 클릭하여 날짜를 입력하세요.'> <input type="text" name="wr_10" id="wr_10" value="<?php echo $wr_6; ?>" class="frm_input"> 시
<input type="radio" name="wr_2" value="여분2-1" <?php echo ($wr_2 == "여분2-1") ? "checked" : "";?>/>여분2-1
<input type="radio" name="wr_2" value="여분2-2" <?php echo ($wr_2 == "여분2-2") ? "checked" : "";?>/>여분2-2
<input type="radio" name="wr_2" value="여분2-3" <?php echo ($wr_2 == "여분2-3") ? "checked" : "";?>/>여분2-3
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="작성완료" class="sm_btn" width="72" height="55" border=0 accesskey='s'></td>
</tr>
</table>
</form>
</div>
<script type="text/javascript" src="<?="$g4[path]/js/jquery.kcaptcha.js"?>"></script>
<script type="text/javascript"> var skin_path = "<?=$board_skin_path?>"; </script>
<script type="text/javascript" src="<?="$board_skin_path/kcaptcha_destroy.js"?>"></script>
<script type="text/javascript">
var save_before = '';
var save_html = document.getElementById('comment_write').innerHTML;
function good_and_write()
{
var f = document.fviewcomment;
if (fviewcomment_submit(f)) {
f.is_good.value = 1;
f.submit();
} else {
f.is_good.value = 0;
}
}
function fviewcomment_submit(f)
{
var pattern = /(^\s*)|(\s*$)/g; // \s 공백 문자
f.is_good.value = 0;
/*
var s;
if (s = word_filter_check(document.getElementById('wr_content').value))
{
alert("내용에 금지단어('"+s+"')가 포함되어있습니다");
document.getElementById('wr_content').focus();
return false;
}
*/
var subject = "";
var content = "";
$.ajax({
url: "<?=$board_skin_path?>/ajax.filter.php",
type: "POST",
data: {
"subject": "",
"content": f.wr_content.value
},
dataType: "json",
async: false,
cache: false,
success: function(data, textStatus) {
subject = data.subject;
content = data.content;
}
});
if (content) {
alert("내용에 금지단어('"+content+"')가 포함되어있습니다");
f.wr_content.focus();
return false;
}
// 양쪽 공백 없애기
var pattern = /(^\s*)|(\s*$)/g; // \s 공백 문자
document.getElementById('wr_content').value = document.getElementById('wr_content').value.replace(pattern, "");
if (char_min > 0 || char_max > 0)
{
check_byte('wr_content', 'char_count');
var cnt = parseInt(document.getElementById('char_count').innerHTML);
if (char_min > 0 && char_min > cnt)
{
alert("코멘트는 "+char_min+"글자 이상 쓰셔야 합니다.");
return false;
} else if (char_max > 0 && char_max < cnt)
{
alert("코멘트는 "+char_max+"글자 이하로 쓰셔야 합니다.");
return false;
}
}
else if (!document.getElementById('wr_content').value)
{
alert("코멘트를 입력하여 주십시오.");
return false;
}
if (typeof(f.wr_name) != 'undefined')
{
f.wr_name.value = f.wr_name.value.replace(pattern, "");
if (f.wr_name.value == '')
{
alert('이름이 입력되지 않았습니다.');
f.wr_name.focus();
return false;
}
}
if (typeof(f.wr_password) != 'undefined')
{
f.wr_password.value = f.wr_password.value.replace(pattern, "");
if (f.wr_password.value == '')
{
alert('패스워드가 입력되지 않았습니다.');
f.wr_password.focus();
return false;
}
}
if (!check_kcaptcha(f.wr_key)) {
return false;
}
return true;
}
/*
jQuery.fn.extend({
kcaptcha_load: function() {
$.ajax({
type: 'POST',
url: g4_path+'/'+g4_bbs+'/kcaptcha_session.php',
cache: false,
async: false,
success: function(text) {
$('#kcaptcha_image')
.attr('src', g4_path+'/'+g4_bbs+'/kcaptcha_image.php?t=' + (new Date).getTime())
.css('cursor', '')
.attr('title', '');
md5_norobot_key = text;
}
});
}
});
*/
function comment_box(comment_id, work)
{
var el_id;
// 코멘트 아이디가 넘어오면 답변, 수정
if (comment_id)
{
if (work == 'c')
el_id = 'reply_' + comment_id;
else
el_id = 'edit_' + comment_id;
}
else
el_id = 'comment_write';
if (save_before != el_id)
{
if (save_before)
{
document.getElementById(save_before).style.display = 'none';
document.getElementById(save_before).innerHTML = '';
}
document.getElementById(el_id).style.display = '';
document.getElementById(el_id).innerHTML = save_html;
// 코멘트 수정
if (work == 'cu')
{
document.getElementById('wr_content').value = document.getElementById('save_comment_' + comment_id).value;
document.getElementById('wr_1').value = document.getElementById('save_comment_wr1_' + comment_id).value;
document.getElementById('wr_2').value = document.getElementById('save_comment_wr2_' + comment_id).value;
document.getElementById('wr_3').value = document.getElementById('save_comment_wr3_' + comment_id).value;
document.getElementById('wr_4').value = document.getElementById('save_comment_wr4_' + comment_id).value;
document.getElementById('wr_5').value = document.getElementById('save_comment_wr5_' + comment_id).value;
document.getElementById('wr_6').value = document.getElementById('save_comment_wr6_' + comment_id).value;
document.getElementById('wr_7').value = document.getElementById('save_comment_wr7_' + comment_id).value;
document.getElementById('wr_8').value = document.getElementById('save_comment_wr8_' + comment_id).value;
document.getElementById('wr_9').value = document.getElementById('save_comment_wr9_' + comment_id).value;
document.getElementById('wr_10').value = document.getElementById('save_comment_wr10_' + comment_id).value;
if (typeof char_count != 'undefined')
check_byte('wr_content', 'char_count');
if (document.getElementById('secret_comment_'+comment_id).value)
document.getElementById('wr_secret').checked = true;
else
document.getElementById('wr_secret').checked = false;
}
document.getElementById('comment_id').value = comment_id;
document.getElementById('w').value = work;
save_before = el_id;
}
if (typeof(wrestInitialized) != 'undefined')
wrestInitialized();
//jQuery(this).kcaptcha_load();
if (comment_id && work == 'c')
$.kcaptcha_run();
}
function comment_delete(url)
{
if (confirm("이 코멘트를 삭제하시겠습니까?")) location.href = url;
}
comment_box('', 'c'); // 코멘트 입력폼이 보이도록 처리하기위해서 추가 (root님)
</script>
<? } ?>
<? if($cwin==1) { ?></td><tr></table><p align=center><a href="javascript:window.close();"><img src="<?=$board_skin_path?>/img/btn_close.gif" border="0"></a><br><br><? } ?>
답변 3
wr_2 id 값을 가진 엘리멘트가 없기 때문에 wr_2부터 아래 줄 싹 ~다 오류가 나는것 같습니다.
(wr_2위에 있는 wr_1과 wr_content는 텍스트 박스 이기 때문에 정상 출력이 되고요)
wr_2를 포함하여 라디오로 되어있는 부분이 많은데 라디오는 항목마다 ID를 같게 부여 할수 없디 때문에 방법을 다르게 해야겠지요.
예를 들어서 wr_2부터 라디오로 되어있는데
document.getElementById('wr_2').value = document.getElementById('save_comment_wr2_' + comment_id).value;
를
radio_wr2 = document.getElementById('save_comment_wr2_' + comment_id).value;
$("input:radio[name='wr_2']:radio[value="+ radio_wr2 + "]").prop("checked", true);
이렇게 변경해보세요.
추가로 그누보드4 이고 제이쿼리 관련 스크립트가 안 불러와져있다면
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
꼭 상단에 넣어주세요.
document.getElementById('wr_1').value = document.getElementById('save_comment_wr1_' + comment_id).value;
document.getElementById('wr_2').value = document.getElementById('save_comment_wr2_' + comment_id).value;
여기서 wr_1은 되고
wr_2는 안 된다는 것인가요?
id 값이 맞는지 확인해 보세요.
해당 페이지 주소(URL)을 한번 올려 보세요.