2016-08-21 9 views
1

私はサポートチケットシステムを作成しようとしています。 https://gyazo.com/f87fde8cfacf2165a373f409954cf653AJAX/PHP - 投稿されたデータを同じページのモーダルに読み込む方法

チェックボックスをオンにすると、ユーザーID(作業中)が選択されます。しかし、緑の返信ボタンがクリックされたときにそのユーザーを選択し、そのユーザーIDに対応する情報を取得して、開いているサポートチケットをすべて表示できるようにしたいと考えています。そして私はモーダルを通して別の返信を加えることができます。ように:https://gyazo.com/6fb77589606b1e24160c52885b987624。しかし、この例では、静的なユーザー名フェッチを使用しています。例えば、どこから支えられたのか:posted_by = 'Chowderrunnah'。 Chowderrunnahはユーザーの名前です。

私は、選択したチェックボックス(作業中)でユーザーIDを取得し、開いているサポートチケットをすべて取得する必要があります。ここで

は私のphpmyadminのデータベースです:https://gyazo.com/f9eb86e2877979182f6a2a35cb6ed5df以下

は私が何を(しよう)しています何のために私のコードですが、動作していません。 PHPタグ内のページの トップへ

function grab_selected_users_support() { 
global $con; 
global $user_reply_id; 
    $username   = $_SESSION['username']; 
    $users_support_sql = "SELECT id, message, posted_by, last_post_by, date_posted, status FROM support WHERE posted_by = 'Chowderrunnah' ORDER BY id DESC"; 
    $result    = $con->query($users_support_sql) or die("Error"); 

     while ($row = mysqli_fetch_assoc($result)) { 

      $usersSupport_id   = $row['id']; 
      $usersSupport_message  = $row['message']; 
      $usersSupport_posted_by  = $row['posted_by']; 
      $usersSupport_last_post_by = $row['last_post_by']; 
      $usersSupport_date_posted = $row['date_posted']; 
      $usersSupport_status  = $row['status']; 

      ?> 

       <div class="well well-sm col-lg-12 pull-left"> 
        <span><strong><?php echo $usersSupport_last_post_by ?></strong>: <?php echo $usersSupport_message; ?><br><br><?php echo $usersSupport_status == 'Open' ? '<span class="label label-success">Open</span>' : '<span class="label label-danger">Closed</span>' ?></b><hr><i><?php echo $usersSupport_date_posted; ?></i></span> 
       </div> 
       <?php ; 
     } 

} 

私のPHPをチェック

<?php 
if(isset($_POST['bulk_delete_submit'])) { 
    if(!empty($_POST['checked_id'])) { 
     $idArr = $_POST['checked_id']; 
     $username = $_SESSION['username']; 
     foreach($idArr as $id) { 
      mysqli_query($con, "DELETE FROM support WHERE id = '$id'"); 
      echo "<p>".$id ."</p>"; 
     } 
     $_SESSION['success_msg'] = 'Support Ticket have been deleted successfully.'; 
     header("Location: admin_support.php"); 
    } 

    else { 
     echo '<div class="row" style="color: red; text-align: center; padding-bottom: 20px;"><i class="fa fa-spin fa-spinner"></i> You must select atleast one support ticket to delete <i class="fa fa-spin fa-spinner"></i></div>'; 
    } 
} 

if(isset($_POST['add_reply_submit'])) { 
    if(!empty($_POST['checked_id'])) { 
     $idArrr = $_POST['checked_id']; 
     $username = $_SESSION['username']; 
     foreach($idArrr as $idd) { 
      $user_reply_id = mysqli_query($con, "SELECT posted_by FROM support WHERE id = '$idd'"); 
     } 
    } 

    else { 
     echo '<div class="row" style="color: red; text-align: center; padding-bottom: 20px;"><i class="fa fa-spin fa-spinner"></i> You must select atleast one support ticket to reply to <i class="fa fa-spin fa-spinner"></i></div>'; 
    } 
} 

?> 

HTMLボタン

<form name="bulk_action_form" action="" class="form-inline" method="POST"/> 

<button type="button" data-toggle="modal" data-target="#myModal" class="btn btn-primary"> 
    <i class="fa fa-info"></i> 
</button> 

<button type="submit" class="btn btn-danger" name="bulk_delete_submit"><i class="fa fa-trash-o"></i></button> 

<button name="add_reply_submit" class="btn btn-success waves-effect waves-light" type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myReplyModal"> 
    <i class="fa fa-reply"></i> 
</button> 

</div> 
</div> 

<div class="table-responsive"> 
<table class="table m-0" id="table"> 

<thead> 
<tr style="font-size: 11px;"> 
<th><input type="checkbox" id="selectall"/></th> 
<th class="table-header">Message</th> 
<th class="table-header">Posted By</th> 
<th class="table-header">Last Post By</th> 
<th class="table-header">Date Posted</th> 
<th class="table-header">Status</th> 
</tr> 
</thead> 
<tbody> 

<?php 
foreach($faq as $k=>$v) { 
?> 
<tr class="table-row" style="text-align: left;" id="no_enter"> 
<td style="font-size: 11px;"><input type="checkbox" name="checked_id[]" class="checkbox" value="<?php echo $faq[$k]["id"]; ?>"></td> 
<td style="font-size: 11px;" contenteditable="true" onBlur="saveToDatabase(this,'message','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["message"] != '' ? $faq[$k]["message"] : 'None'; ?></td> 
<td style="font-size: 11px;" contenteditable="true" onBlur="saveToDatabase(this,'posted_by','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["posted_by"] != '' ? $faq[$k]["posted_by"] : 'None'; ?></td> 
<td style="font-size: 11px;" contenteditable="true" onBlur="saveToDatabase(this,'last_post_by','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["last_post_by"] != '' ? $faq[$k]["last_post_by"] : 'None'; ?></td> 
<td style="font-size: 11px;" contenteditable="true" onBlur="saveToDatabase(this,'date_posted','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["date_posted"] != '' ? $faq[$k]["date_posted"] : 'None'; ?></td> 
<td style="font-size: 11px;" contenteditable="true" onBlur="saveToDatabase(this,'status','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["status"] != '' ? ($faq[$k]["status"] == 'Open' ? '<span class="label label-success">Open</span>' : '<span class="label label-danger">Closed</span>') : 'None'; ?></td> 
<?php 
} 
?> 

</tbody> 
</table> 
</div> 
</div> 
</form> 

マイモーダル

 <!-- Reply to ticket modal --> 
<div id="myReplyModal" class="modal fade" role="dialog"> 
    <div class="modal-dialog"> 

    <!-- Modal content--> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal">&times;</button> 
     <h4 class="modal-title">Modal Header</h4> 
     </div> 
     <div class="modal-body"> 
     <form class="form-horizontal" role="form" method="post"> 
      <?php grab_selected_users_support(); ?> 
      <div class="row"> 
       <div class="col-sm-12"> 
        <div class="text-center p-20"> 
         <button class="btn w-sm btn btn-primary waves-effect" type="submit" name="addReply">Save Changes</button> 
         <button type="button" class="btn w-sm btn-danger waves-effect" data-dismiss="modal" aria-hidden="true">Close</button> 
        </div> 
       </div> 
      </div> 
     </form> 
     </div> 
     <div class="modal-footer"> 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
     </div> 
    </div> 

    </div> 
</div> 
+0

フォームに「

+0

質問を改善することができます。 [最小、完全、および検証可能な例](http://stackoverflow.com/help/mcve)をお読みください。あなたのコードが何も特別な問題であなたの正確な問題を示すとき、あなたはボランティアしてあなたを助ける人たちに敬意を表しています。また、コードをスクロールする必要がないように書式設定することで、役立つことができます。 – zhon

答えて

0

あなたのform内部<button>を使用しています。それはjavascriptで動作することができますが、PHPのみでは、POSTリクエストでは動作しません。
buttonタグをinputタグに変更する必要があります。

<input type="submit" name="bulk_delete_submit"> 

<input type="submit" name="add_reply_submit"> 

ボタンのタグに追加したクラスを追加すると、そのスタイルが変更されることがあります。

そうでなければ、このようなクラスのデザインを変更することができます。

<style> 
input[type="submit"] 
{ 
color:black; 
font-size: 10px; 
padding: 10px; 
}//This style is just an example to show you how to that how to change style of input type submit 
</style> 

ご希望の場合はお手数ですが、

関連する問題