Skip to content

Instantly share code, notes, and snippets.

@CrabAss
Last active September 24, 2020 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CrabAss/5ccef1340a70c5567d3a291ab27c77ef to your computer and use it in GitHub Desktop.
Save CrabAss/5ccef1340a70c5567d3a291ab27c77ef to your computer and use it in GitHub Desktop.
Simple Postboy

Description

This is a simple utility to perform form POST submit to anywhere.

License

MIT License

Copyright (c) 2020 CrabAss

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Simple Postboy</title>
<style>
body {
font-family: Tahoma, Helvetica, sans-serif;
}
form {
margin: 32px 0;
}
label {
width: 120px;
padding: 8px 0;
}
.field > input[type='text'] {
display: inline-block;
flex: 1;
padding: 8px;
}
.field, .btn {
display: flex;
margin: 8px;
}
.btn {
justify-content: center;
margin-top: 16px;
}
.btn > input[type='submit'] {
padding: 8px 24px;
font-size: 12pt;
}
</style>
</head>
<body>
<form method="post" onsubmit="onSubmit(this)">
<div class="field">
<label for="url">URL:</label>
<input type="text" id="url" placeholder="https://www.example.com/...">
</div>
<div class="field">
<label for="query">Query String:</label>
<input type="text" id="query" placeholder="a=1&b=2&...">
</div>
<div class="btn">
<input type="submit" value="Submit using POST" />
</div>
</form>
<script>
function onSubmit(form) {
form.action = document.getElementById('url').value
const queries = document.getElementById('query').value.split('&')
queries.forEach(q => {
const inputElement = document.createElement('input')
inputElement.name = q.split('=')[0]
inputElement.value = q.split('=')[1]
inputElement.hidden = true
form.appendChild(inputElement)
})
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment