Jump to content

Recommended Posts

Hi i am working on a comment module where i need to display in my text area which user I am replying to.

Check out the attached screenshot.

If I click the REPLY button next to user 'nopicguy, It should insert @nopicguy followed or preceeded by a line break in the text area below.

If I click the REPLY button next to user 'airtest', it should insert @airtest followed or preceeded by a line break and so on.

Now right now the reply button just takes you to the text area.

 

Below is the code snippet of the module. If anybody requires the complete section code, I can PM you. Thanks in advance..

 

Posted: 
<?php echo date("F j, Y",$comment_date); ?>  •  <?php echo date("h:i A",$comment_date); ?>
<?php echo $comment_message;?>
<?php if($comment_userid==$loggedinuserid || $ismoderator=="YES") 
{ ?>
   <div class="comment-report"> 
   <form action="" name="deleteform<?php echo $commentid; ?>" method="post"><input type='hidden' name='do' value='deletecomment'><input type='hidden' value='<?php echo $commentid; ?>' name='delete_comment_id'>
      <a href="javascript:void(0)" onClick="document.deleteform<?php echo $commentid; ?>.submit();"><strong>Delete</strong>
      </a> 
   </form>
   </div>
 <?php 
 } ?>
     <a rel="nofollow" href="javascript:void(0)" onclick="window.open('<?php echo $root_url."reportthis.php?url=".urlencode("http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]); ?>', 'mywindow','location=1,status=1,scrollbars=1, width=400,height=300'); return false;">
     <img src="<?php echo $root_url; ?>images/report-button.png" align="top" border="0">
     </a> 
 <a rel="nofollow" href="#addcomment"><img src="<?php echo $root_url; ?>images/reply-button.png" align="top" border="0">
 </a>
  
   <?php if($loggedin=="YES") 
   { ?>
   <?php echo "<input type='image' src='".$root_url."images/submitcomment-button.png' value='Submit' name='comment_create'>"; ?><?php 
   } ?>
  
  
//Takes you to the text area 
<a name="addcomment"></a>
<form class='form' action='' method='post' name='edit' class='nomarginform'>
POST A COMMENT
  <?php if($loggedin=="YES") { ?>
   
  <?php } ?>
   
    <?php if($loggedin=="YES") { ?><textarea class='comment-input-textarea-loggedin' name='comments_content'></textarea><div class='clearboth'></div><?php } ?>
    <?php if($loggedin=="YES") { ?><div class='comment-submit-holder'><div class='comment-submit'><?php echo "<input type='image' src='".$root_url."images/submitcomment-button.png' value='Submit' name='comment_create'>"; ?>
  
  <input type='hidden' name='comment_create' value='YES'>
  <input type='hidden' name='thread_comment_id' value='<?php echo $thread_comment_id; ?>'>
</div>
</form>

 

 

Link to comment
https://forums.phpfreaks.com/topic/245461-reply-comments-to-multiple-usernames/
Share on other sites

There isn't any clue in your code where that functionality is trying to happen, or is it me? There should be a Javascript code that takes the username of the original author, prepends an "@" to it and writes it in the comment field. The following code, using jQuery for rapid prototyping, does all that. You'll notice that I've put the author in the "rel" attribute of the reply anchor, something that normally should be set dynamically for each reply button - that's the way I chose for this example, but you can retrieve it with other means, such as reading the html of the element (ex: $('p.author').html()).

 

<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('a.reply').click(function(){
	comment = $('#comment');
	author = '@' + $(this).attr('rel');
	comment.val(comment.val() + author);
	return false;
});
});
</script>
</head>

<body>
<a href="#reply" rel="php_begins" class="reply">Reply</a>
<textarea id="comment"></textarea>
</body>
</html>

 

Try it and if it's what you're seeking, feel totally free to use and modify it. The only thing it's missing is giving focus to the textarea after the reply button is pushed. I intentionally left it that way because simple and plain focus() will place the caret (cursor) at the beginning of the textarea and it's ugly. It can be easily coded to place the caret at the end of the text with a jQuery plugin.

well i used a simple javascript function and it worked for me..it goes something like this:

<script type="text/javascript">
function setComments(userID) {
    document.getElementById("comments_content").value = document.getElementById("comments_content").value + userID + "\n\n";
}
</script>

 

<a onclick="setComments('<?php print $comment_username; ?>')" rel="nofollow" href="#addcomment"><img src="<?php echo $root_url; ?>images/reply-button.png" align="top" border="0"></a>

 

<?php if($loggedin=="YES") { ?><textarea class='comment-input-textarea-loggedin'  id='comments_content' name='comments_content'></textarea></div><?php } ?>
    

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.