Created
February 7, 2024 14:08
-
-
Save beardedtim/7e03757be346f1ab4985aadca1173322 to your computer and use it in GitHub Desktop.
Example form action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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