0
For each post, I have a feedback form. What I need to do is pass the form ID to the script, in order to handle the comment in the respective POST.
But to pass the value to the div
process, I would need to somehow put the ID of the new comment in this div
, so that when there is another comment, the div
not replaced but added.
This form is sent by pressing the button Enter. I need to know how to send the POST ID inside the script to get it $("#myForm"+ valorId).ajaxForm({
instead of $("#myForm9").ajaxForm({
.
Do you have any way to send the following result with a div
, so that this div
of id="processa'.$commentId.'
be shown instead of calling a div
already defined with fixed ID ?
echo '
<span>'.$posting.'</span><div class="cimg_box"><img class="comment_img" src="css/images/profile_photo/'.$user['photo'].'"/></div>';
};
Complete code:
if ($rows > 0){
echo '<div class="comment_all clearfix" style="display: none" id="reply_box'.$post['id_p'].'">';
while($comment = mysqli_fetch_assoc($query3)){
echo '
<div class="comment_box">
<span>'.$comment['text'].'</span><div class="cimg_box"><img class="comment_img" src="css/images/profile_photo/'.$comment['photo'].'"/></div>
</div>';
}
echo '
<div id="processa" class="comment_box">
</div>
</div>';
}
echo '
<div class="comm_box_reply" >
<div class="reply_box"><img class="img_friend2" src="css/images/profile_photo/'.$user['photo'].'"/>
<form id="myForm'.$post['id_p'].'" value="'.$post['id_p'].'" name="rform" class="reply_form" action="processing.php" method="post">
<textarea name="editor1" id="text'.$post['id_p'].'" onclick="rpbox(this.id, '.$post['id_p'].')" class="imagem_news" placeholder="Your Comment..." ></textarea>
<input name="formValue" type="text" value="'.$post['id_p'].'" hidden/>
</form>
</div>
</div>
$(document).ready(function() {
$("#processa").hide();
$("#myForm9").ajaxForm({ /*Preciso modificar aqui para colocar a id do post*/
target: "#processa",
success: function(){
$("#processa").show();
}
});
});`
<?php
include("config.php");
if ($_POST['editor1'] != ''):
$uid = $_SESSION['userId'];
$postId = $_POST["formValue"];
if((isset($_POST["editor1"])) ? $_POST["editor1"] : ''){
$posting = (isset($_POST["editor1"])) ? $_POST["editor1"] : '';
$date = date("Y-m-d H:i:s");
$sql = "INSERT INTO comments (id_c, post_id, author_id , text, date) values ('', '$postId', '$uid', '$posting', '$date')";
mysqli_query($conn,$sql);
$query4 = mysqli_query($conn,"SELECT * FROM `profile` WHERE `id` = '$uid'") or die(mysqli_error($conn));
$user = mysqli_fetch_array($query4);
$proc = mysqli_insert_id($conn);
echo '
<span>'.$posting.'</span><div class="cimg_box"><img class="comment_img" src="css/images/profile_photo/'.$user['photo'].'"/></div>';
};
else:
echo 'Error!';
endif;
?>
A tip, which I find interesting. Separate the following files: HTML, php (dao and controller) and Jquery.
– adventistaam
for me it was not very clear... the question of the id pro ajax I would do like this: $. ajax({ (...) data: { 'pathname': $("#myForm"+ valueId)
– aa_sp
@Yes, they are separated.
– Marciohrm
@aa_sp I have a set of posts, and each of these posts is open to comments. To post the comment, I use js with the enter key instead of a button. I need to get the form id, for example, to be able to handle this form in specific.
– Marciohrm
For example, this
echo 'div...
you would only bring the result to ajax, and ajax would feed into your html page– adventistaam
@adventistaam the problem is that when returns the result, the script shows only the last output sent instead of giving the append. Another thing is that only updates for who is seeing and not for everyone.
– Marciohrm
In this case you can use the Pusher to see the warning for everyone
– adventistaam