#Handle values with FormData
1 messages · Page 1 of 1 (latest)
Based on the information provided in the extracts, you can use the FormData.get() method to retrieve the values from your FormData object. However, it's important to note that FormData only supports string values. If you want to retrieve data in a specific format (like number or Date), you might need to use a library like zod-form-data to validate the request and retrieve data in the format you prefer.
Here's an example of how you can read the FormData:
export async function POST(request: Request) {
const formData = await request.formData()
const name = formData.get('name')
const email = formData.get('email')
return Response.json({ name, email })
}
(Source: Next.js Documentation (https://nextjs.org/docs/app/building-your-application/routing/route-handlers#request-body-formdata))
However, the provided extracts do not contain enough information to guide you on how to structure your FormData to match the exact format you want. You might need to adjust your code to ensure that the data is appended to the FormData object in the desired structure.