-
Hi, I've built a form builder that allows creating forms directly in a CMS, which automatically generates a form page. My server action then receives the user's formData, fetches the corresponding form fields from the CMS, and creates a dynamic Zod validation schema. I started moving my server actions to next-safe-action, but as far as I understand, it’s not possible to generate a dynamic Zod validation schema at runtime. Because of this, I plan to continue generating and validating the forms directly in the server action code. However, to achieve this, I need access to the raw input of the submitted form—meaning the entire formData, not just the fields already validated by the Zod schema, which cannot anticipate all the fields that might be submitted. Here is an example of what I would need: const accessFormSchema = zfd.formData(
z.object({
birthdate: z.string(),
file_ref: z.string(),
form_id: z.coerce.number(),
})
)
export type accessFormSchemaVE = z.inferFlattenedErrors<typeof accessFormSchema>['fieldErrors']
export const accessForm = publicAction
.metadata({ actionName: 'accessForm' })
.schema(accessFormSchema)
.action(async ({ parsedInput, rawInput }) => {
const { birthdate, file_ref, form_id } = parsedInput
// generate zod schema here and validate form fields from rawInput
}) Thanks in advance for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey, I released v7.10.2 which adds |
Beta Was this translation helpful? Give feedback.
Hey, I released v7.10.2 which adds
clientInput
andbindArgsClientInputs
props to the server code function callback object argument. You should be able to access raw inputs passed from the client inside of it from now on.