diff --git a/api/src/services/contacts/contacts.js b/api/src/services/contacts/contacts.js
index a36cf89..36edc66 100644
--- a/api/src/services/contacts/contacts.js
+++ b/api/src/services/contacts/contacts.js
@@ -1,3 +1,4 @@
+import { validate } from '@redwoodjs/api'
import { db } from 'src/lib/db'
export const contacts = () => {
@@ -11,6 +12,7 @@ export const contact = ({ id }) => {
}
export const createContact = ({ input }) => {
+ validate(input.email, 'email', { email: true })
return db.contact.create({
data: input,
})
diff --git a/web/src/pages/ContactPage/ContactPage.js b/web/src/pages/ContactPage/ContactPage.js
index be00375..0ee8876 100644
--- a/web/src/pages/ContactPage/ContactPage.js
+++ b/web/src/pages/ContactPage/ContactPage.js
@@ -3,10 +3,12 @@ import { toast, Toaster } from '@redwoodjs/web/toast'
import {
FieldError,
Form,
+ FormError,
Label,
- TextField,
Submit,
TextAreaField,
+ TextField,
+ useForm,
} from '@redwoodjs/forms'
const CREATE_CONTACT = gql`
@@ -18,9 +20,11 @@ const CREATE_CONTACT = gql`
`
const ContactPage = () => {
+ const formMethods = useForm({ mode: 'onBlur' })
const [create, { loading, error }] = useMutation(CREATE_CONTACT, {
onCompleted: () => {
toast.success('Thank you for your submission!')
+ formMethods.reset()
},
})
@@ -33,7 +37,8 @@ const ContactPage = () => {