Skip to content

Instantly share code, notes, and snippets.

@oharsta
Created November 8, 2024 09:57
Show Gist options
  • Save oharsta/8a18a7f204a24e3e08db82a3927ed380 to your computer and use it in GitHub Desktop.
Save oharsta/8a18a7f204a24e3e08db82a3927ed380 to your computer and use it in GitHub Desktop.
Post JS form programmatically
const formPost = (fields, path) => {
const form = document.createElement("form");
form.method = "POST";
form.action = path;
Object.entries(fields).forEach(field => {
const hiddenField = document.createElement("input");
hiddenField.type = "hidden";
hiddenField.name = field[0];
hiddenField.value = field[1];
form.appendChild(hiddenField);
});
document.body.appendChild(form);
form.submit();
}
export function startFlow(scope, path) {
formPost({scope}, path)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment