Validates a form submission.
Validates a site visitor's form submission and returns any validation violations.
Site visitors can see the validation violations on their forms. For example, notification messages can appear on the screen.
function validateSubmission(
options: Options,
context: Context,
): Promise<FormSubmissionResponse>;
Submission validation options.
Metadata about the request.
This example validates a form submission. The message text box has a limitation of 200 characters.
const options = {
submission: {
formId: "e9e8c6ff-a771-401b-b46e-82f7c742ef3d",
},
};
export const validateSubmission = async (options, context) => {
const messageValidation = options.submission.submissions["long_answer_3524"];
const messageLengthlimit = 200;
if (messageValidation.length > messageLengthlimit) {
return {
errors: [
{
errorPath: "long_answer_3524",
customErrorMessage: "Message cannot exceed 200 characters!",
},
],
};
} else {
return {};
}
};
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.