I created simple form element on my website. It looked like this:
<form method="post">
<input name="firstname"/>
<input name="lastname"/>
<input type="submit"/>
</form>
After pressing submit button I got 501 with text
Not Implemented
Next.js only handles rendering, if you want to handle data coming into the app you have to implement your own routes for that using a custom server
I have the same issue, but my problem is when I run nextjs with prod with npm run build;npm run start and my form into onSubmit function use a function ajax for send data to my api server, the page shows "Not Implement", but not is always only in few cases <Form name="PasswordRestoreForm" method="POST" onSubmit={handleSubmit(values =>{restorePass(values);})}>
<Field
label="Correo electr贸nico"
name="email"
placeholder="Correo electr贸nico"
disabled={sendIn}
component={TextField}
validate={[Validations.email, Validations.required]}
/>
<div className="divider" />
<SubmitButton className="button-lg btn-main" style={{width: '100%'}} disabled={sendIn} text={sendIn ? 'Enviando' : 'Enviar'} />
</Form>
You probably have to add event.preventDefault()
@timneutkens I am using Redux Forms and with "handleSubmit" does call to "preventDefault" default
@timneutkens I think it's a valid question. I compiled my app that has client and server. Client basically has pages so it's a frontend. And server is custom express server. I created build with next build ./client and then started with next start ./client. The server runs fine. Now, I have a login page and accepts email and password. I try to submit login form and it returns 501 - Not Implemented while I was expecting it to work with next build. Perhaps there's still something I don't get. Can you please let me know what could be missing? How can deploy my app to production with my current setup.
I think this issue should be changed to a feature request. I want it too but this test would suggest that it's intentionally not supported:
btw two things are being conflated above:
event.preventDefault() suggestion is what you'd need to hijack the traditional form post action and submit using javascript without a page reload. For option 2, triggering a form post to a next.js page should be possible but apparently is not (yet). I guess I'll build a web service as a workaround (option 1)
Most helpful comment
@timneutkens I think it's a valid question. I compiled my app that has
clientandserver. Client basically haspagesso it's a frontend. And server is custom express server. I created build withnext build ./clientand then started withnext start ./client. The server runs fine. Now, I have a login page and accepts email and password. I try to submit login form and it returns501 - Not Implementedwhile I was expecting it to work with next build. Perhaps there's still something I don't get. Can you please let me know what could be missing? How can deploy my app to production with my current setup.