[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live)

[Help](/c/help/9)

# Form clearing on submit in Next.js

87 views · 0 likes · 2 posts


Jeannie (@that-jeannie) · 2024-08-08

Ok, I may not understand the true purpose of the `revalidatePath` function.

I am trying to clear a form's fields after the form is submitted, but using `revalidatePath` in a Server Actions file has no effect - nothing happens.

The actions are imported into the form, which is then imported into a page. Also, the form successfully sends the data to my Vercel Postgres store.

How can I get the form to actually reset (clear the fields) after submission?

/actions/actions.js file I'm testing with:

```
"use server"

import prisma from "/lib/prisma"
import { revalidatePath } from "next/cache";

export async function createRando(formData) {
    await prisma.InternetRando.create({
        data: {
            rando_name: formData.get('name'),
            rando_email: formData.get('email'),
            rando_message: formData.get('message'),
        }
    });

    revalidatePath('/contact', 'page')
}
```

Thanks for any guidance!


Amy Egan (@amyegan) · 2024-08-08

Hi @that-jeannie! If I understand you correctly, the goal is to clear form data on the page rather than to rebuild a cached page for all visitors. In that case [revalidatePath](https://nextjs.org/docs/app/api-reference/functions/revalidatePath) would not the right tool for the job.

You can find relevant info about [forms](https://nextjs.org/docs/pages/building-your-application/data-fetching/forms-and-mutations) and [server actions](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations) in the Next.js docs. You can also find some potential solutions posted here: https://github.com/vercel/next.js/discussions/58448.