Getting weird error in the form action by using Server Action #56234
Replies: 12 comments 9 replies
-
You must declare
|
Beta Was this translation helpful? Give feedback.
-
Latest update on nextjs demo commerce store using experimental feature of react: Throws same error when button is disabled. You can see it here if you inspect disabled button:
|
Beta Was this translation helpful? Give feedback.
-
I encountered this bug earlier. The cause is that I was passing a handler function just like I would on a onSubmit handler. I realized it was a mistake. You can only pass the action directly to the action attribute. Do not pass any handlers whatsoever. ❌ const onSubmitHandler = (formData: FormData) => {
// do something
actionHandler(formData)
}
<form action={onSubmitHandler}></form> ☑️
I hope this helps someone who face the same issue. |
Beta Was this translation helpful? Give feedback.
-
I got this error because I had both This is WRONG:
Correct:
|
Beta Was this translation helpful? Give feedback.
-
i got this when i tried to automate 100+ signup submissions using fetch api. i guess that's not possible with server actions. here's my code: rate-limit/utils.tsimport { parse } from 'node-html-parser'
export const LOCALHOST_URL = 'http://localhost:3000'
export async function getActionNo(): Promise<string> {
const res = await fetch(`${LOCALHOST_URL}/signup`)
const html = await res.text()
const $ = parse(html)
const str = $.querySelector('input[name="$ACTION_1:0"]')
?.getAttribute('value')
?.toString() as string
const data = JSON.parse(str)
return data.id
} rate-limit/signup.tsimport { LOCALHOST_URL, getActionNo } from 'rate-limit/utils'
async function main() {
const actionNumber = await getActionNo()
const formData = new FormData()
formData.append('email', 'a@a.com')
const res = await fetch(`${LOCALHOST_URL}/signup`, {
method: 'POST',
credentials: 'same-origin',
body: formData,
headers: {
'Next-Action': actionNumber,
},
})
const data = await res.text()
console.log({ res, data })
}
main() I'm still trying it here but I think I have to use Puppeteer/Playwright with it. Idk if there's an easier alternative. |
Beta Was this translation helpful? Give feedback.
-
I added In other places, I was using |
Beta Was this translation helpful? Give feedback.
-
Issue is still there. All you have to do is navigate from one route to the route that contains the |
Beta Was this translation helpful? Give feedback.
-
I had the same issue: some of my forms were throwing an error The answer was simple: I had this |
Beta Was this translation helpful? Give feedback.
-
I have this error in every |
Beta Was this translation helpful? Give feedback.
-
Thanx to @gumpen. For me solution was to add 'use client' in submit component. Double check all form elements in you for. If form is a Client component, all children must be Client component with |
Beta Was this translation helpful? Give feedback.
-
Any news with this? none of the solutions here seemed to help. I don't have any nested forms, I have 'use client' where it needs to be, anytime I use the router (or link) to route to a component with a form, I get this error, no matter what. |
Beta Was this translation helpful? Give feedback.
-
javascript:throw new Error('A React form was unexpectedly submitted. If you called form.submit() manually, consider using form.requestSubmit() instead. If you're trying to use event.stopPropagation() in a submit event handler, consider also calling event.preventDefault().')"
Beta Was this translation helpful? Give feedback.
All reactions