add ajax to found form
This commit is contained in:
parent
df470b370f
commit
935d48f6f7
3 changed files with 36 additions and 4 deletions
2
ajax.php
2
ajax.php
|
@ -29,7 +29,7 @@ switch($_GET["action"]) {
|
|||
$errormsg = "all values have to be set";
|
||||
}
|
||||
break;
|
||||
case "insert":
|
||||
case "add_found":
|
||||
if (hasval($_POST["was"]) && hasval($_POST["wann"]) && hasval($_POST["wo"])) {
|
||||
/* Prepared statement, stage 1: prepare */
|
||||
if (!($stmt = $mysqli->prepare("INSERT INTO items(was, wann, wo) VALUES (?, ?, ?)"))) {
|
||||
|
|
|
@ -19,6 +19,15 @@
|
|||
<li class="breadcrumb-item active">Add</li>
|
||||
</ol>
|
||||
|
||||
<div id="alertmessage" class="collapse alert alert-danger" role="alert">
|
||||
This is a danger alert—check it out!
|
||||
</div>
|
||||
|
||||
|
||||
<div id="successmessage" class="collapse alert alert-success" role="alert">
|
||||
A simple success alert—check it out!
|
||||
</div>
|
||||
|
||||
<!-- Area Chart Example-->
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
|
@ -26,11 +35,11 @@
|
|||
Insert Item into DB
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="/action.php?action=insert">
|
||||
<form method="POST" action="/action.php?action=add_found" id="found_form">
|
||||
<p><input type="text" class="form-control" placeholder="WANN" name="wann" value="<?php echo date("Y-m-d H:i:s");?>"></p>
|
||||
<p><input type="text" class="form-control" placeholder="WO" name="wo"></p>
|
||||
<p><input type="text" class="form-control" placeholder="WAS" name="was"></p>
|
||||
<p><input type="submit" class="form-control"></p>
|
||||
<p><button type="submit" class="form-control" onclick="testajax(); return false;">Submit</button></p>
|
||||
</form>
|
||||
</div>
|
||||
<div class="card-footer small text-muted">Updated yesterday at 11:59 PM</div>
|
||||
|
@ -40,6 +49,29 @@
|
|||
<!-- /.container-fluid -->
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
function testajax(){
|
||||
$.post( "/ajax.php?action=add_found", $( "#found_form" ).serialize() ).done(function( data ) {;
|
||||
reply = JSON.parse(data);
|
||||
if(reply.status == "ok"){
|
||||
$( "#lost_form" ).trigger("reset");
|
||||
$("#alertmessage").collapse('hide');
|
||||
$("#successmessage").html(reply.message).collapse('show');
|
||||
}else{
|
||||
$("#successmessage").collapse('hide');
|
||||
$("#alertmessage").html(reply.message).collapse('show');
|
||||
}
|
||||
}).fail(function() {
|
||||
$("#successmessage").collapse('hide');
|
||||
$("#alertmessage").html("error").collapse('show');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Bootstrap core JavaScript-->
|
|
@ -21,7 +21,7 @@
|
|||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/insert/">
|
||||
<a class="nav-link" href="/found/">
|
||||
<i class="fas fa-fw fa-plus"></i>
|
||||
<span>Found</span>
|
||||
</a>
|
||||
|
|
Loading…
Reference in a new issue