Skip to content

Instantly share code, notes, and snippets.

@Om4ar
Created November 17, 2017 01:07
Show Gist options
  • Save Om4ar/48b095167c43370841a1a973a86a9325 to your computer and use it in GitHub Desktop.
Save Om4ar/48b095167c43370841a1a973a86a9325 to your computer and use it in GitHub Desktop.
confirmation box and confirm a form before send a post request ( req.body ) / get request ( req.query )
<form action="/profile" method="post" id="myForm" >
<div class="form-group input-group-lg ">
<input type="hidden" name="dashboard" value="lock">
</div>
<input type="button" value="lock DashBoard" onclick="lockFunction()" class=" btn btn-danger btn-lg btn-fill">
</form> <!-- Dashboard lock form -->
// this is a dependecy for the confiramtion box http://bootboxjs.com/
<script src="/assets/js/bootbox.min.js" type="text/javascript"></script>
function lockFunction(){
bootbox.confirm({
title: "Destroy planet?",
message: "Do you want to activate the Deathstar now? This cannot be undone.",
buttons: {
cancel: {
label: '<i class="fa fa-times"></i> Cancel'
},
confirm: {
label: '<i class="fa fa-check"></i> Confirm'
}
},
callback: function (result) {
if (result === true) {
document.getElementById("myForm").submit();
}
console.log('This was logged in the callback: ' + result);
}
});
}
// YOU Should start a server here and then control the route .. you will get the answer on req.body
// user profile route
router.post("/profile" , function(req, res) {
console.log(req.body);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment