채택완료

목록에서 코멘트 작성

2016-06-28 (화) 23:17:09 3,738

http://sir.kr/g5_plugin/1443?sfl=wr_subject%7C%7Cwr_content&stx=ajax 

목록에서 ajax 방식으로 댓글작성을 하고싶어서.. 스킨을 수정해보고 있는데요

-------------------------------------------

A글

코멘트작성폼

코멘트작성폼

B글

C글

코멘트작성폼

-------------------------------------------

위와같이 코멘트작성폼이 제대로 뜨지도않고 작동도 안돼요..

사실 view_comment_skin의 작성폼 소스를 list_skin에 그대로 붙여넣은거라 작동이 안될거란건 예상했는데 어떻게 수정해야할지 모르겠습니다ㅠㅠ

질문이 막연한거같지만 뭘 수정해야할지 힌트라도 주실수 있을까요ㅠㅠ

Copy
<?php if ($is_comment_write) {    if($w == '')        $w = 'c';?><!-- 댓글 쓰기 시작 { --><aside id="bo_vc_w">    <h2>댓글쓰기</h2>    <form name="fviewcomment" action="" method="post" autocomplete="off" id="fviewcomment">    <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 class="tbl_frm01 tbl_wrap">        <table>        <tbody>        <?php if ($is_guest) { ?>        <tr>            <th scope="row"><label for="wr_name">이름<strong class="sound_only"> 필수</strong></label></th>            <td><input type="text" name="wr_name" value="<?php echo get_cookie("ck_sns_name"); ?>" id="wr_name" required class="frm_input required" size="5" maxLength="20"></td>        </tr>        <tr>            <th scope="row"><label for="wr_password">비밀번호<strong class="sound_only"> 필수</strong></label></th>            <td><input type="password" name="wr_password" id="wr_password" required class="frm_input required" size="10" maxLength="20"></td>        </tr>        <?php } ?>        <tr>            <th scope="row"><label for="wr_secret">비밀글사용</label></th>            <td><input type="checkbox" name="wr_secret" value="secret" id="wr_secret"></td>        </tr>        <?php if ($is_guest) { ?>        <tr>            <th scope="row">자동등록방지</th>            <td><?php echo $captcha_html; ?></td>        </tr>        <?php } ?>        <?php        if($board['bo_use_sns'] && ($config['cf_facebook_appid'] || $config['cf_twitter_key'])) {        ?>        <tr>            <th scope="row">SNS 동시등록</th>            <td id="bo_vc_send_sns"></td>        </tr>        <?php        }        ?>        <tr>            <th scope="row">내용</th>            <td>                <?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>            </td>        </tr>        </tbody>        </table>    </div>     <div class="btn_confirm">        <input type="submit" id="btn_submit" class="btn_submit" value="댓글등록">    </div>     </form></aside> <script>$(function() {	var working = false;	$('#fviewcomment').submit(function(e)	{		e.preventDefault();		var f = e.target; 		var pattern = /(^\s*)|(\s*$)/g; // \s 공백 문자 		f.is_good.value = 0; 		var subject = "";		var content = "";		$.ajax({			url: g5_bbs_url+"/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;			}		} 		<?php if($is_guest) echo chk_captcha_js();  ?> 		if(working) return false;		working = true; 		$.ajax({			url: g5_bbs_url+"/write_comment_update.php",			type: 'post',			data: $(this).serialize(),			success: function (data) {				working = false;				var arr = $.parseJSON(data); 				if(arr.status == 1) //최하층 입력인 경우				{					$('#bo_vc_empty').remove();					$("#captcha_reload").trigger("click");					$("#captcha_key").val("");					document.getElementById('wr_content').value = "";					$(arr.html).hide().appendTo($('#bo_vc')).slideDown();				}				else if(arr.status == 2) //대댓글 입력인 경우				{					comment_box('', 'c');					$("#captcha_reload").trigger("click");					$("#captcha_key").val("");					$(arr.html).hide().insertAfter('#bo_vc article#c_'+arr.id).slideDown();				}				else if(arr.status == 3) //수정				{					comment_box('', 'c');					$("#captcha_reload").trigger("click");					$("#captcha_key").val("");					$('#c_'+arr.id+' p').fadeOut("fast", function(){						$(this).html(arr.content);						$(this).fadeIn("fast");						$('#save_comment_'+arr.id).html(arr.content1);												console.log(arr.secret, arr.id);						if (arr.secret) {							document.getElementById('secret_comment_'+arr.id).value = "secret";						} else {							document.getElementById('secret_comment_'+arr.id).value = "";						}					});				}				else //실패				{					alert('실패');				}			}		});	});}); var save_before = '';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)    {		$("#fviewcomment").appendTo($('#'+el_id));		        // 댓글 수정        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;        }		else		{			 document.getElementById('wr_content').value = "";		}         document.getElementById('comment_id').value = comment_id;        document.getElementById('w').value = work;         if(save_before)            $("#captcha_reload").trigger("click");         save_before = el_id;    }} function comment_delete(href){    if (confirm("이 댓글을 삭제하시겠습니까?")) {				if (href.split("/")[4].split("?")[0] == "password.php")		{			document.location.href = href;		}		else		{			var data = href.split("?")[1];			var id = href.split("comment_id=")[1].split("&")[0]; 			$.ajax({				url: g5_bbs_url+"/delete_comment.php",				type: 'post',				data: data,				success: function() {								if($("#c_"+id+" form").length) {						comment_box('', 'c'); //수정의 경우					}					$("#c_"+id).slideUp(function(){ $(this).remove(); });				}			});		}	}}	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;    }} comment_box('', 'c'); // 댓글 입력폼이 보이도록 처리하기위해서 추가 (root님) <?php if($board['bo_use_sns'] && ($config['cf_facebook_appid'] || $config['cf_twitter_key'])) { ?>// sns 등록$(function() {    $("#bo_vc_send_sns").load(        "<?php echo G5_SNS_URL; ?>/view_comment_write.sns.skin.php?bo_table=<?php echo $bo_table; ?>",        function() {            save_html = document.getElementById('bo_vc_w').innerHTML;        }    );});<?php } ?></script><?php } ?><!-- } 댓글 쓰기 끝 -->
|

답변 1개

채택된 답변
+20 포인트

혹시 댓글등록은 잘되나요?

생각보다 복잡한데 스크립트 오류확인부터 해보셔야할듯하구요.!

그냥 등록은 iframe으로 처리하시고..등록후 가지고 오는것만 ajax로 하심이 훨신 간편할듯 예상됩니다.

답변을 작성하려면 로그인이 필요합니다.