Created
November 17, 2017 01:07
-
-
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 )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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