Created
          November 8, 2024 09:57 
        
      - 
      
- 
        Save oharsta/8a18a7f204a24e3e08db82a3927ed380 to your computer and use it in GitHub Desktop. 
    Post JS form programmatically
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | 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