2016-04-06 14 views
2

モーダルフォームを使用して現在のテーブルを作成したいが、動作しません。私はちょっとした助けが必要です。私はここで何か逃したかもしれません。ありがとう!ここでブートストラップモーダルフォームを使用したADDが機能していません

は、ボタンの私のコードです:

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addModal" href="add_dept.php">+ Add Department</button> 

ここに私のコードは、モーダルコンテンツを表示するために私のファイルの一番下にあります:

<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> 
<div class="modal-dialog" role="document"> 
    <div class="modal-content"> 
    </div> 
</div> 

ここadd_deptための私のコードです。 ph:

<?php include("../includes/config.php"); 
$reqErr = ""; 
if($_SERVER['REQUEST_METHOD'] == "POST") { 
    if(!empty($_POST['dept_name']) && !empty($_POST['dept_code'])) { 
    $dept_name = $_POST['dept_name']; 
    $dept_code = $_POST['dept_code']; 
    $query_addDept = "INSERT INTO department(dept_name,dept_code) VALUES('$dept_name','$dept_code')"; 
    if(mysqli_query($con,$query_addDept)) { 
     $reqErr = '<div class="alert alert-success" id="myAlert"> 
       <a href="" class="close"> &nbsp; <i class="fa fa-times"></i></a> 
      <i class="fa fa-check-circle"></i> Department added</div>'; 
      mysqli_close($con); 
    } 
    else { 
     $reqErr = '<div class="alert alert-danger" id="myAlert"> 
      <a href="" class="close"> &nbsp; <i class="fa fa-times"></i></a> 
      <i class="fa fa-exclamation-circle"></i> Failed to add Department</div>'; 
    } 
    } 
} 
?> 

<?php echo $reqErr; ?> 
<div class="modal-header"> 
    <button type="button" class="close" data-dismiss="modal">&times;</button> 
    <h4 class="modal-title">Add Department</h4> 
</div> 
<div class="modal-body"> 
    <form method="POST" class="form" id="add-department" role="form"> 
    <div class="form-group"> 
    <input type="text" class="form-control" id="dept_name" name="dept_name" placeholder="Department Name" /> 
    <span class="help-block"></span> 
    </div> 
    <div class="form-group"> 
    <input type="text" class="form-control" id="dept_code" name="dept_code" placeholder="Department Code" /> 
    <span class="help-block"></span> 
    </div> 
    <div class="modal-footer"> 
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
    <input type="submit" id="submit_btn" class="btn btn-primary" /> 
    </div> 
    </form> 
</div> 
+0

チェックこの回答をhttp://stackoverflow.com/questions/32433765/how-to-pass-をget-variables-from-a-bootstrapmodalを使用してデータベースからIDを取得し、それをモーダルに渡してレコードを更新します – Shehary

答えて

1
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addModal" href="add_dept.php">+ Add Department</button> 

のhref = ""

<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> 
    <div class="modal-dialog" role="document"> 
     <div class="modal-content"> 
       <?php require_once('add_dept.php'); ?> 
     </div> 
    </div> 
</div> 

が最後の追加、削除 - 近くのdiv

+0

これは機能しました!ありがとう。私はボタン内でhrefとdata-targetを一緒に使うことができないからです。行を更新したい場合、どのように行IDをモーダルに転送しますか?ありがとう –

+0

あなたは歓迎です:) – bfahmi

1
data-target="#addModal" href="add_dept.php" 

ここに問題があります。

ボタンをモデルトリガーとしても、作成ページへのリンクとしても設定することはできません。

モーダルをトリガし、モーダルをもう一度クリックしたり、add_dept.phpページにリダイレクトしたり、モーダルを使わずにクリックだけをリダイレクトすることができます。

関連する問題