Use `action` attribute on `form` element.
See original GitHub issueBug, Feature, or Question?
Question
Stupid question but is it possible to use action='/api' method='POST'
instead of ajax
? I am trying to use it but its not working for me. Is there a prop
I have to supply?
- Formik Version: 0.11.11
- React Version: 16.2.0
- TypeScript Version: N/A
- CodeSandbox Link: N/A
- OS: Mac OS X 10.13.3
- Node Version: 8.0.0
- Package Manager and Version: NPM, 5.8.0
Issue Analytics
- State:
- Created 5 years ago
- Comments:20
Top Results From Across the Web
HTML form action Attribute - W3Schools
The action attribute specifies where to send the form-data when a form is submitted. Browser Support. Attribute. action, Yes, Yes, Yes, Yes, Yes ......
Read more >HTML form action Attribute - Dofactory
The action attribute on a <form> tag specifies the form-handler that will process the submitted form data. Form data is submitted to a...
Read more >HTML| action Attribute - GeeksforGeeks
The HTML | action Attribute is used to specify where the form data is to be sent to the server after the submission...
Read more >The Form element - HTML: HyperText Markup Language | MDN
Attributes for form submission · If the value of the method attribute is post , enctype is the MIME type of the form...
Read more >Setting the Form Action with a JavaScript Function
In an HTML form, the action attribute is used to indicate where the form's data is sent to when it is submitted. The...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I feel sorry for anyone who stumbles across this thread because they are in for a world of confusion.
The answer to the original questions is yes you can use
action='/api' method='POST'
instead of ajax and the working demo is here: https://codesandbox.io/s/826qv6lv7l ✌️Glad you asked! Straight from Formik’s README:
Even when using HTML forms, one can still draw value from Formik for 1 and 2.
I disagree with your premise here. Formik is an extension of React and React is designed to control the DOM. Even the React Forms docs show that React itself doesn’t get in the way of initiating the default form submission event. Quite the opposite in fact, because you the developer need to explicitly call
e.preventDefault()
if you want to handle the form submission viaxhr
.One reason why Formik prevents the default form submission is because Formik supports asynchronous validation via the
validate
function. If the form’sonSubmit
returns, then the default submission would occur before the async validation has a chance to run. Given that, the only way that I can see to use Formik with HTML form posts is to submit the form via javascript yourself:Full demo here: https://codesandbox.io/s/826qv6lv7l