Skip to content

Instantly share code, notes, and snippets.

@beardedtim
Created February 7, 2024 14:08
Show Gist options
  • Save beardedtim/7e03757be346f1ab4985aadca1173322 to your computer and use it in GitHub Desktop.
Save beardedtim/7e03757be346f1ab4985aadca1173322 to your computer and use it in GitHub Desktop.
Example form action
'use server'
import { sql } from '@vercel/postgres'
import { Log } from '@/utils'
const handleFormSubmit = async (data: FormData) => {
const message = data.get('message') as string
const email = data.get('email') as string
const phoneNumber = data.get('phone') as string
const name = data.get('name') as string
try {
await sql`INSERT INTO contact_requests(name, message, email, phonenumber) VALUES (${name}, ${message}, ${email}, ${phoneNumber});`
Log.info('Successfully saved message to database')
} catch (err) {
Log.warn({ err }, 'There was an error saving the data to the database')
}
}
export default handleFormSubmit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment