Ich möchte ein modales Formular verwenden, um meine aktuelle Tabelle zu füllen, aber es wird nicht funktionieren. Ich brauche nur etwas Hilfe, ich könnte hier etwas verpasst haben. Vielen Dank!ADD mit Bootstrap Modal Formular funktioniert nicht
Hier ist mein Code für die Schaltfläche:
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addModal" href="add_dept.php">+ Add Department</button>
Hier ist mein Code in der Tiefe meiner Datei den modalen Inhalt anzuzeigen:
<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>
Hier ist mein Code für add_dept. php:
<?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"> <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"> <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">×</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>
Check diese Antwort http://stackoverflow.com/questions/32433765/how-to-pass- get-variables-from-a-link-zu-a-bootstrapmodal holt die ID aus der Datenbank, übergibt sie modal und aktualisiert den Datensatz dagegen – Shehary