Right ok, I have set up news blogs on the front of my website and you can click on them to see further details and the comments. You can post a comment using the following piece of code on the announcements page:
<form name="postComment" method="post" action="TheProcess.php">
<div id="AnnouncementComments">
<? if($session->logged_in && !$session->banned && !$session->suspended){ ?>
<div class="post">
<textarea cols="76" rows="4" onfocus="this.value=''" style="border:1px solid black;" name="comment"><? if($POST['comment']){ echo $POST['comment']; }else{ echo "Post a comment..."; } ?></textarea>
<input class="button" type="submit" value="Submit" />
<input type="hidden" name="newcomment" value="1" />
<input type="hidden" name="announcementid" value="<? echo $AnnouncementId; ?>" />
<? echo $form->error("comments"); ?>
</div>
<? } ?>
</form>
I'll come to this bit in a minute:
<textarea cols="76" rows="4" onfocus="this.value=''" style="border:1px solid black;" name="comment"><? if($POST['comment']){ echo $POST['comment']; }else{ echo "Post a comment..."; } ?></textarea>
Ok, that works and comments are submitted using coding contained in TheProcess.php. Now in each comment, I have an options drop down box containing options such as delete comment, report comment, edit comment. When one of these buttons is pressed, it activates this code on TheProcess.php page:
function actionComment(){
global $session, $form, $database;
$CommentId = $_POST['commentid'];
$CommentInfo = $database->getInfoComment($CommentId);
$AnnouncementId = $CommentInfo['announcement_id'];
$Action = $_POST['actions'];
if($Action == 'moderate'){
if($session->isNewMod()){
header("Location: moderate.php?type=comment&id=$CommentId");
}else{
$field = "commentactions";
$form->setError($field, "You don not have permission to moderate this comment");
header("Location: announcements.php?id=$AnnouncementId");
}
}else{
$retval = $session->actionComment($CommentId, $Action);
header("Location: announcements.php?id=$AnnouncementId");
}
}
Now my action is edit, so I'm now referred to $session->actionComment.
<?
function actionComment($CommentId, $Action){
global $form, $database;
//CommentId is the comment to be actioned
//Announcementid is the id of the announcement
//Poster is the poster of the comment
$CommentInfo = $database->getInfoComment($CommentId);
$Comment = $CommentInfo['comment'];
$AnnouncementId = $CommentInfo['announcement_id'];
$Poster = $CommentInfo['poster'];
if($Action == 'edit' && ($session->isNewMod() || $Poster == $session->username)){
?>
<form method="post" name="announcements.php">
<input type="hidden" name="comment" value="<? echo $Comment; ?>" />
<script>javascript:this.form.submit();</script>
</form>
<?
}else{
$field = "commentactions";
$form->setError($field, "You do not have permission to edit this comment");
}
What I want is for when the user clicks edit, they can edit their comment in the original box they posted in it and then hit submit again? So what I tried was for in the $session->actionComment, I sent a variable back then in the original announcements page. I said if this variable exists, then display it in the textarea. This didn't work, so does anyone have any ideas how I could get to this to work?
Sorry for the long-winded question and I look forward to hearing your suggestions 🙂