add ajax to found form

This commit is contained in:
/jedi/ 2018-12-30 13:26:45 +01:00
parent df470b370f
commit 935d48f6f7
3 changed files with 36 additions and 4 deletions

View file

@ -29,7 +29,7 @@ switch($_GET["action"]) {
$errormsg = "all values have to be set"; $errormsg = "all values have to be set";
} }
break; break;
case "insert": case "add_found":
if (hasval($_POST["was"]) && hasval($_POST["wann"]) && hasval($_POST["wo"])) { if (hasval($_POST["was"]) && hasval($_POST["wann"]) && hasval($_POST["wo"])) {
/* Prepared statement, stage 1: prepare */ /* Prepared statement, stage 1: prepare */
if (!($stmt = $mysqli->prepare("INSERT INTO items(was, wann, wo) VALUES (?, ?, ?)"))) { if (!($stmt = $mysqli->prepare("INSERT INTO items(was, wann, wo) VALUES (?, ?, ?)"))) {

View file

@ -19,6 +19,15 @@
<li class="breadcrumb-item active">Add</li> <li class="breadcrumb-item active">Add</li>
</ol> </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--> <!-- Area Chart Example-->
<div class="card mb-3"> <div class="card mb-3">
<div class="card-header"> <div class="card-header">
@ -26,11 +35,11 @@
Insert Item into DB Insert Item into DB
</div> </div>
<div class="card-body"> <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="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="WO" name="wo"></p>
<p><input type="text" class="form-control" placeholder="WAS" name="was"></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> </form>
</div> </div>
<div class="card-footer small text-muted">Updated yesterday at 11:59 PM</div> <div class="card-footer small text-muted">Updated yesterday at 11:59 PM</div>
@ -40,6 +49,29 @@
<!-- /.container-fluid --> <!-- /.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--> <!-- Bootstrap core JavaScript-->

View file

@ -21,7 +21,7 @@
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="/insert/"> <a class="nav-link" href="/found/">
<i class="fas fa-fw fa-plus"></i> <i class="fas fa-fw fa-plus"></i>
<span>Found</span> <span>Found</span>
</a> </a>