댓글 수정 취소 부문 구현...

댓글 수정 취소 부문 구현...

QA

댓글 수정 취소 부문 구현...

본문

view.comment.skin.php 화일에서


<?php if($list[$i]['is_reply'] || $list[$i]['is_edit'] || $list[$i]['is_del']) {
            $query_string = clean_query_string($_SERVER['QUERY_STRING']);
            if($w == 'cu') {
                $sql = " select wr_id, wr_content, mb_id from $write_table where wr_id = '$c_id' and wr_is_comment = '1' ";
                $cmt = sql_fetch($sql);
                if (!($is_admin || ($member['mb_id'] == $cmt['mb_id'] && $cmt['mb_id'])))
                    $cmt['wr_content'] = '';
                $c_wr_content = $cmt['wr_content'];
            }
            $c_reply_href = './board.php?'.$query_string.'&c_id='.$comment_id.'&w=c#bo_vc_w';
            $c_edit_href = './board.php?'.$query_string.'&c_id='.$comment_id.'&w=cu#bo_vc_w';
         ?>
<footer>
            <ul class="bo_vc_act">
                <?php if ($list[$i]['is_reply'] && $is_admin) { ?><li><a href="<?php echo $c_reply_href;  ?>" onclick="comment_box('<?php echo $comment_id ?>', 'c'); return false;">답변</a></li><?php } ?>
                <?php if ($list[$i]['is_edit']) { ?><li><a href="<?php echo $c_edit_href;  ?>" onclick="comment_box('<?php echo $comment_id ?>', 'cu'); return false;">수정</a></li><?php } ?>
                <?php if ($list[$i]['is_del'])  { ?><li><a href="<?php echo $list[$i]['del_link'];  ?>" onclick="return comment_delete();">삭제</a></li><?php } ?>
            </ul>
        </footer>

여기 부분에서 수정버튼을 누르면 댓글 등록창이 나오고, 아래에 수정 삭제 메뉴가 떠 있더라구요...

이것을 수정버튼을 누르면 댓글등록창은 그대로 나오고, 취소 삭제 메뉴로 바꾸고 싶은데, 조건을 어떻게 주어야 할지 몰라 이렇게 글을 남깁니다. 글이 수정상태인것을 알면 될 것 같은데요... 아 그리고, 취소버튼을 댓글등록창을 닫고 싶은데, on click="history.back()" 이걸로 주어야 할까요? 실력이 짧아 약간의 지식이라도 얻어가려고 글을 남깁니다...

이 질문에 댓글 쓰기 :

답변 6

"view_comment.skin.php" 100라인 부근을 보시면 아래와 같은 내용이 있을 거에요.(form~/form 사이)

 

 


    <span class="sound_only">내용</span>
    <?php if ($comment_min || $comment_max) { ?><strong id="char_cnt"><span id="char_count"></span>글자</strong><?php } ?>
 
<!-- 바로 아래 html  1줄 추가 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓  -->
<a id="cancel" href="javascript:comment_box('', 'c');" style="display:none">취소</a>

    <textarea id="wr_content" name="wr_content" maxlength="10000" required class="required" title="내용" placeholder="댓글내용을 입력해주세요" 
    <?php if ($comment_min || $comment_max) { ?>onkeyup="check_byte('wr_content', 'char_count');"<?php } ?>><?php echo $c_wr_content; ?></textarea>
 

 

 

 

위 1줄 추가하시고 페이지 하단 script 단 270 라인 부근을 보시면  "if (work == 'cu') {" 라는 수정관련 스크립트에 다시 아래와 같은 1줄을 넣어 주세요.

 

 

 

 
        // 댓글 수정
        if (work == 'cu')
        {
            document.getElementById('wr_content').value = document.getElementById('save_comment_' + comment_id).value;
          // 바로 아래 js 1줄 추가 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 
          document.getElementById("cancel").style.display = "block"; // 추가+++

            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;
        }
 

 

 

 

이제 테스트해 보시면 감이 오실거에요.  

오전에 올려놓고 갈걸 그랬습니다. 즐작하세요!

묵공님 죄송합니다... 혼자 해결해 볼려고, 했는데 잘 안 되어서 글을 남겨요...

화일이 커서 줄인다고 했는데, 확인이 가능한지 모르겠어요....

$w=''; 새글상태에서, 수정이 보이려면 이게 맞을것 같고요... 수정버튼을 누르면, $w='cu'; 로 바꾸어져야 하는것 아닌가요? 수정상태에서 취소를 활성화 시킬려고 하는데, 넘 어렵네요...

시간이 되시면 한번만 도와주시면 감사하겠습니다. 이틀째 고민하다가 너무 안풀려서요...

취소버튼 누를때 comment_box('','c'); 이것은 맞는 것 같아요... 그런데, 활성화 자체가 안 되어서...


<?php
    <article id="c_<?php echo $comment_id ?>" <?php if ($cmt_depth) { ?>style="margin-left:<?php echo $cmt_depth ?>px;border-top-color:#e0e0e0"<?php } ?>>
        <header style="z-index:<?php echo $cmt_sv; ?>">
            <h1 class="user_comment"><?php echo get_text($list[$i]['wr_name']); ?>님의 댓글</h1>
            <?php echo $list[$i]['name'] ?>
            <?php if ($cmt_depth) { ?><img src="<?php echo $board_skin_url ?>/img/icon_reply.gif" class="icon_reply" alt="댓글의 댓글"><?php } ?>
            <?php if ($is_ip_view) { ?>
            아이피
            <span class="bo_vc_hdinfo"><?php echo $list[$i]['ip']; ?></span>
            <?php } ?>
           
            <span class="bo_vc_hdinfo"><time datetime="<?php echo date('Y-m-d\TH:i:s+09:00', strtotime($list[$i]['datetime'])) ?>"><?php echo $list[$i]['datetime'] ?></time></span>
   <?php
            include(G5_SNS_PATH.'/view_comment_list.sns.skin.php');
            ?>
        </header>
        <!-- 댓글 출력 -->
        <p>
   <?php if (strstr($list[$i]['wr_option'], "secret")) { ?><img src="<?php echo $board_skin_url; ?>/img/icon_secret.gif" alt="비밀글"><?php } ?>
            <?php echo $comment ?>
        </p>
        <span id="edit_<?php echo $comment_id ?>"></span><!-- 수정 -->
        <span id="reply_<?php echo $comment_id ?>"></span><!-- 답변 -->
        <input type="hidden" value="<?php echo strstr($list[$i]['wr_option'],"secret") ?>" id="secret_comment_<?php echo $comment_id ?>">
        <textarea id="save_comment_<?php echo $comment_id ?>" style="display:none"><?php echo get_text($list[$i]['content1'], 0) ?></textarea>
        <?php if($list[$i]['is_reply'] || $list[$i]['is_edit'] || $list[$i]['is_del']) {
            $query_string = clean_query_string($_SERVER['QUERY_STRING']);
            if($w == 'cu') {
                $sql = " select wr_id, wr_content, mb_id from $write_table where wr_id = '$c_id' and wr_is_comment = '1' ";
                $cmt = sql_fetch($sql);
                if (!($is_admin || ($member['mb_id'] == $cmt['mb_id'] && $cmt['mb_id'])))
                    $cmt['wr_content'] = '';
                $c_wr_content = $cmt['wr_content'];
            }
            $c_reply_href = './board.php?'.$query_string.'&c_id='.$comment_id.'&w=c#bo_vc_w';
            $c_edit_href = './board.php?'.$query_string.'&c_id='.$comment_id.'&w=cu#bo_vc_w';
         ?>
        <footer>
            <ul class="bo_vc_act">
                <?php if ($list[$i]['is_reply'] && $is_admin) { ?><li><a href="<?php echo $c_reply_href;  ?>" onclick="comment_box('<?php echo $comment_id ?>', 'c'); return false;">답변</a></li><?php } ?>
                <?php if ($list[$i]['is_edit']) { if($w == '')  { ?>
     <li><a href="<?php echo $c_edit_href;  ?>" onclick="comment_box('<?php echo $comment_id ?>', 'cu'); return false;">수정</a></li>
     <?php }else{ ?>
     <li><a href="<?php echo $c_edit_href;  ?>" onclick="comment_box('', 'c'); return false;">취소</a></li>
     <?php } ?>
     <?php } ?>
                <?php if ($list[$i]['is_del']) { ?><li><a href="<?php echo $list[$i]['del_link'];  ?>" onclick="return comment_delete();">삭제</a></li><?php } ?>
            </ul>
        </footer>
        <?php } ?>
    </article>
    <?php } ?>
    <?php if ($i == 0) { //댓글이 없다면 ?><p id="bo_vc_empty">등록된 댓글이 없습니다.</p><?php } ?>
</section>
<!-- } 댓글 끝 -->
<?php if ($is_comment_write) {
    if($w == '')
        $w = 'c';
?>
<!-- 댓글 쓰기 시작 { -->
<aside id="bo_vc_w">
    <h2>댓글쓰기</h2>
 <form name="fviewcomment" action="./write_comment_update.php" onsubmit="return fviewcomment_submit(this);" method="post" autocomplete="off">
    <input type="hidden" name="w" value="<?php echo $w ?>" id="w">
    <input type="hidden" name="bo_table" value="<?php echo $bo_table ?>">
    <input type="hidden" name="wr_id" value="<?php echo $wr_id ?>">
    <input type="hidden" name="comment_id" value="<?php echo $c_id ?>" id="comment_id">
    <input type="hidden" name="sca" value="<?php echo $sca ?>">
    <input type="hidden" name="sfl" value="<?php echo $sfl ?>">
    <input type="hidden" name="stx" value="<?php echo $stx ?>">
    <input type="hidden" name="spt" value="<?php echo $spt ?>">
    <input type="hidden" name="page" value="<?php echo $page ?>">
    <input type="hidden" name="is_good" value="">
  <div id="comment_form">
  <div class="write_body">
   <? if($is_guest) { ?>
   <div class="bo_vc_form">
    <ul>
     <li><input type="text" name="wr_name" value="<?php echo get_cookie("ck_sns_name"); ?>" id="wr_name" required class="i_text required" maxLength="20" placeholder="이름"></li>
     <li><input type="password" name="wr_password" id="wr_password" required class="i_text required" maxLength="20" placeholder="password"></li>
     <li><?php echo $captcha_html; ?></li>
    </ul>
   </div>
   <? } ?>
   <div class="no_editor">
    <?php if ($comment_min || $comment_max) { ?><strong id="char_cnt"><span id="char_count"></span>글자</strong><?php } ?>
                <textarea id="wr_content" name="wr_content" maxlength="10000" required class="required" title="내용"
                <?php if ($comment_min || $comment_max) { ?>onkeyup="check_byte('wr_content', 'char_count');"<?php } ?>><?php echo $c_wr_content;  ?></textarea>
                <?php if ($comment_min || $comment_max) { ?><script> check_byte('wr_content', 'char_count'); </script><?php } ?>
                <script>
                $(document).on( "keyup change", "textarea#wr_content[maxlength]", function(){
                    var str = $(this).val()
                    var mx = parseInt($(this).attr("maxlength"))
                    if (str.length > mx) {
                        $(this).val(str.substr(0, mx));
                        return false;
                    }
                });
                </script>
   </div>
   <div class="f_wrap">
    <div class="fl">
     <span class="checkbox"><input type='checkbox' id='wr_secret' name='wr_secret' value='secret' /> <label for='wr_secret' class='wr_secret_label'>비밀글</label></span>
    </div>
    <div class="fr">
     <input type="submit" id="btn_submit" class="btn_submit" value="댓글등록">
    </div>     
   </div>
  </div>
 </div>
 </form>
</aside>

<script>
var save_before = '';
var save_html = document.getElementById('bo_vc_w').innerHTML;
 
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 = 'bo_vc_w';
    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;
            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;
        if(save_before)
            $("#captcha_reload").trigger("click");
        save_before = el_id;
    }
}

</script>
<?php } ?>
답변을 작성하시기 전에 로그인 해주세요.
전체 11
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT