Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@transcend-io/contact-form-schema

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@transcend-io/contact-form-schema

Schema for the marketing contact form.

  • 0.1.0
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
decreased by-4.77%
Maintainers
2
Weekly downloads
 
Created
Source

contact-form-schema

A zod schema for the marketing contact form.

npm install contact-form-schema

Usage

Validate user-inputted ContactFormFields on the contact form client.

import { zodResolver } from '@hookform/resolvers/zod';
import { ContactFormFields } from '@transcend-io/contact-form-schema';
import { useForm } from 'react-hook-form';

const App = () => {
  const {
    register,
    handleSubmit,
    formState: { errors },
  } = useForm({
    resolver: zodResolver(ContactFormFields),
  });

  return (
    <form onSubmit={handleSubmit((d) => console.log(d))}>
      <input {...register('firstName')} />
      {errors.firstName?.message && <p>{errors.firstName?.message}</p>}
      <input {...register('email')} />
      {errors.email?.message && <p>{errors.email?.message}</p>}
      {/* ... */}
      <input type="submit" />
    </form>
  );
};

Validate the POST body in the contact form handler.

import { ContactFormBody } from '@transcend-io/contact-form-schema';

export default async function contactFormHandler(
  req: NextApiRequest,
  res: NextApiResponse<ContactFormResponse>
) {
  // [[Perform authentication]]

  // Validation
  const result = ContactFormBody.safeParse(req.body);
  if (!result.success) {
    return res.status(400).json({ error: result.error.message });
  }
  const contactFormBody = result.data;

  // [[Perform business logic]]
}

FAQs

Package last updated on 14 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc