0
JavaScriptから編集データ用のフォームを作成したいです。リンク編集をクリックすると、編集データの編集フォームが表示されます。phpおよびjavascriptフォーム編集データを作成できますか?
これは、出品者の出品者です。
<form id="form-edit" method="post">
<?php
$sql = "SELECT * FROM comment WHERE question_id = $question_id ORDER BY id DESC";
$r1 = mysqli_query($link, $sql);
while($cm = mysqli_fetch_array($r1)) {
$comment_id = $cm['id'];
echo '<section class="section-comment">';
echo '<span class="commentator">' .$cm['user_id'] . '</span>';
echo $cm['detail'];
// This is link Edit
echo '<a href="#" class="edit-comment" edit-id="'.$comment_id.'">Edit</a>';
echo $comment_id; //This can show correct comment_id
?>
<div id="form-edit-dialog">
<input type="text" name="user_id" value="<?php echo $user_id ?>" readonly > <br>
//I add this line for check comment_id but it show max comment_id to min when I open and close form
<input type="text" name="id" value="<?php echo $comment_id ?>" readonly > <br>
<textarea name="detail"></textarea><br>
<button type="submit" id="submit-edit">Submit</button>
<input type="hidden" name="comment_id" id="comment-id">
}
</form>
</div>
このようなコードのJavaスクリプトを作成します。
$(function() {
$('a.edit-comment').click(function(event) { //Click link Edit
$('#form-edit')[0].reset();
event.preventDefault();
var t = "Edit Comment";
$('#form-edit-dialog').dialog({
width: '600px',
title: t,
modal: true,
position: { my: "center", at: "center", of: window}
});
//set value for hidden
$('#comment-id').val($(this).attr('edit-id'));
});
$('#submit-edit').click(function() {
$('form#form-edit').ajaxForm({
url: 'save-edit.php',
type: 'post',
dataType: 'script',
beforeSend: function() {
$.blockUI({message:'<h3>Sending data...</h3>'});
},
complete: function() {
$.unblockUI();
}
});
});
});
PHPはすべてのコメントを一覧表示し、正しくcomment_id示すが、私は編集でクリックしたときに、私は、フォームを閉じて、もう一度[編集]をクリックしたとき、それはcomment_idの最大数を表示することができます。 comment_idは、comment_idがなくなるまでcomment_id番号を減らします。 phpやjavascriptを使ってフォーム編集データを作成できますか、新しいページにデータを送信する必要がありますか?