在我的网站中,我显示了本地人的列表,每个我都有一个显示更多信息的模态。在这种模式中,我可以查看用户的评论并插入评论。所有信息和数据都来自我的数据库。 在插入评论表单中有3个可编辑的字段:
type="text"
作为评论标题使用第一个本地,一切正常,用户可以正确插入评论。与其他当地人一样,存在一个问题:
如果我点击代表我的费率的星号,用户输入就不起作用,所以我无法选择投票,而且我无法插入评论,因为如果我点击提交按钮,我的评论不会被插入,因为缺少投票。
echo' <div class="col-sm-12" id="recensioni_titolo">
<form role="form" id="review-form" method="post" action="php\insert_comment.php">
<div class="row">
<div class="col-sm-8">
<div class="form-group">
<input type="text" class="form-control" name="Titolo" id="titolo_review" placeholder="Titolo">
<input type="text" class="form-control" name="ID_locale" id="titolo_review" value="'.$id_Local.'" style="visibility: hidden; position:fixed;">
</div>
</div>
<div class="col-sm-4">
<fieldset class="rating form-group-">
<input type="radio" id="star5" name="Voto" value="5" /><label class = "full" for="star5" title="Ottimo - 5 stelle"></label>
<input type="radio" id="star4" name="Voto" value="4" /><label class = "full" for="star4" title="Buono - 4 stelle"></label>
<input type="radio" id="star3" name="Voto" value="3" /><label class = "full" for="star3" title="Discreto - 3 stelle"></label>
<input type="radio" id="star2" name="Voto" value="2" /><label class = "full" for="star2" title="Insufficiente - 2 stelle"></label>
<input type="radio" id="star1" name="Voto" value="1" /><label class = "full" for="star1" title="Pessimo - 1 stella"></label>
</fieldset>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<textarea class="form-control textarea" rows="3" name="Review" id="review" placeholder="Inserisci una descrizione.."></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button type="button" class="btn main-btn pull-right" id="submit_review">Invia</button>
</div>
</div>
</form>
</div>';
<?php
session_start();
require 'connect.php';
if(isset($_POST['Titolo'])) {
$title_rew = $conn->real_escape_string($_POST['Titolo']);
}
if(isset($_POST['Voto'])) {
$voto_rew = $conn->real_escape_string($_POST['Voto']);
}
if(isset($_POST['Review'])) {
$review_rew = $conn->real_escape_string($_POST['Review']);
}
if(isset($_POST['ID_locale'])) {
$id_rew = $conn->real_escape_string($_POST['ID_locale']);
}
$current_date = date('Y-m-d');
$sql = "INSERT INTO recensione (ID_Recensione,Titolo_R, Voto_R, Commento_R, IDnegozio_R, Email_R, Utente_R, Data_R)
VALUES (DEFAULT, '$title_rew', '$voto_rew', '$review_rew','$id_rew','".$_SESSION['emailSessione']."','".$_SESSION['usernameSessione']."','$current_date')";
$result = mysqli_query($conn,$sql) or die(mysqli_error($conn));
$conn->close();
?>
#submit_review
$("#submit_review").unbind().click(function() {
var chx = document.getElementsByName("Voto");
for (var i=0; i<chx.length; i++) {
// If you have more than one radio group, also check the name attribute
// for the one you want as in && chx[i].name == 'choose'
// Return true from the function on first match of a checked item
if (chx[i].type == 'radio' && chx[i].checked) {
$.ajax({
url : "php/insert_comment.php",
type : "post",
data : $("#review-form").serialize(),
success : function(data){
$.ajax({
url : "php/reviews.php",
type : "post",
data: {'id_Local' : $('.modal').attr('data-modal')},
success : function(data){
$('#box_recensioni').html(data);
}
})
}
})
return true;
}
}
// End of the loop, return false
alert("Inserisci almeno il voto!!")
return false;
});