available over at GitHub<\/a>.<\/p>\n\n\n Bonus<\/h3>\n\n\n
The following code includes everything we covered as well as the logic for setting a custom subject line with what was submitted in the name field.<\/p>\n\n\n\n
import React, { useState } from \"react\";\nimport { useRouter } from \"next\/router\";\n \nconst ContactPage = () => {\n const [submitterName, setSubmitterName] = useState(\"\");\n const router = useRouter();\n const confirmationScreenVisible =\n router.query?.success && router.query.success === \"true\";\n const formVisible = !confirmationScreenVisible;\n \n const ConfirmationMessage = (\n <React.Fragment>\n <p>\n Thank you for submitting this form. Someone should get back to you\n within 24-48 hours.\n <\/p>\n \n <button onClick={() => router.replace(\"\/contact\", undefined, { shallow: true })}> Submit Another Response <\/button>\n <\/React.Fragment>\n );\n \n const ContactForm = (\n <form\n className=\"container\"\n method=\"POST\"\n name=\"contact-form\"\n action=\"contact\/?success=true\"\n data-netlify=\"true\"\n data-netlify-honeypot=\"bot-field\"\n >\n <input\n type=\"hidden\"\n name=\"subject\"\n value={`You've got mail from ${submitterName}`}\n \/>\n <input type=\"hidden\" name=\"form-name\" value=\"contact-form\" \/>\n <p hidden>\n <label>\n Don\u2019t fill this out: <input name=\"bot-field\" \/>\n <\/label>\n <\/p>\n \n <label htmlFor=\"name\">Name *<\/label>\n <input\n id=\"name\"\n name=\"name\"\n required\n onChange={(e) => setSubmitterName(e.target.value)}\n type=\"text\"\n \/>\n <label htmlFor=\"company\">Company *<\/label>\n <input id=\"company\" name=\"company\" required type=\"text\" \/>\n <label htmlFor=\"email\">E-mail Address *<\/label>\n <input id=\"email\" type=\"email\" name=\"email\" required \/>\n <label htmlFor=\"message\">Message *<\/label>\n <textarea id=\"message\" name=\"message\" required\/>\n <button type=\"submit\">Submit<\/button>\n <\/form>\n );\n \n return (\n <div>\n <h1>Contact Us<\/h1>\n{formVisible ? ContactForm : ConfirmationMessage}\n <\/div>\n );\n};\n \nexport default ContactPage;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"We’re going to create a contact form with Next.js and Netlify that displays a confirmation screen and features enhanced spam detection. Next.js is a powerful React framework for developing performant React applications that scale. By integrating a Next.js site with Netlify\u2019s technology, we can quickly get a working contact form up and running without having […]<\/p>\n","protected":false},"author":286052,"featured_media":353131,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":"","jetpack_publicize_message":"How to Create a Contact Form With Next.js and Netlify by @indigitalcolor","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":[]},"categories":[4],"tags":[595,1415,557],"jetpack_publicize_connections":[],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2021\/10\/Screen-Shot-2021-09-19-at-3.36.18-PM.png?fit=2048%2C1122&ssl=1","jetpack-related-posts":[{"id":293530,"url":"https:\/\/css-tricks.com\/using-netlify-forms-and-netlify-functions-to-build-an-email-sign-up-widget\/","url_meta":{"origin":353128,"position":0},"title":"Using Netlify Forms and Netlify Functions to Build an Email Sign-Up Widget","date":"August 2, 2019","format":false,"excerpt":"Building and maintaining your own website is a great idea. Not only do you own your platform, but you get to experiment with web technologies along the way. Recently, I dug into a concept called serverless functions, starting with my own website. I\u2019d like to share the results and what\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2019\/08\/netlify-icons.png?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":270959,"url":"https:\/\/css-tricks.com\/forms-auth-and-serverless-functions-on-gatsby-and-netlify\/","url_meta":{"origin":353128,"position":1},"title":"Forms, Auth and Serverless Functions on Gatsby and Netlify","date":"May 31, 2018","format":false,"excerpt":"Abstracting infrastructure is in our DNA. Roads, schools, water supply networks\u2014you get the idea. Web development is no exception: serverless architectures are a beautiful expression of that phenomenon. Static sites, in particular, are turning into dynamic, rich experiences. Handling static forms, authentication, and backend functions on statically-generated sites is now\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2018\/05\/gatsby-netlify.jpg?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":330998,"url":"https:\/\/css-tricks.com\/netlify-next-js\/","url_meta":{"origin":353128,"position":2},"title":"Netlify & Next.js","date":"December 14, 2020","format":false,"excerpt":"Cassidy Williams has been doing a Blogvent (blogging every day for a month) over on the Netlify Blog. A lot of the blog posts are about Next.js. There is a lot to like about Next.js. I just pulled one of Cassidy's starters for fun. It's very nice that it has\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2020\/12\/nextplugin.png?fit=1200%2C694&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":350253,"url":"https:\/\/css-tricks.com\/architecting-with-next-js\/","url_meta":{"origin":353128,"position":3},"title":"Architecting With Next.js","date":"August 24, 2021","format":false,"excerpt":"Free event hosted by Netlify coming up next week (Wednesday, August 25th): Architecting with Next.js. It's just a little half-day thing. No brainer. Join us for a special event where we'll highlight business teams using Next.js in production, including architecture deep dives, best practices and challenges. Next.js is the fastest-growing\u2026","rel":"","context":"In "Sponsored"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2021\/08\/OG-Image-No-details-No-CTA.png?fit=1200%2C630&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":335526,"url":"https:\/\/css-tricks.com\/next-js-on-netlify\/","url_meta":{"origin":353128,"position":4},"title":"Next.js on Netlify","date":"February 28, 2021","format":false,"excerpt":"If you want to put Next.js on Netlify, here's a 5 minute tutorial\u00b9. One of the many strengths of Next.js is that it can do server-side rendering (SSR) with a Node server behind it. But Netlify does static hosting not Node hosting, right? Well Netlify has functions, and those functions\u2026","rel":"","context":"In "Sponsored"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":353066,"url":"https:\/\/css-tricks.com\/building-a-tennis-trivia-app-with-next-js-and-netlify\/","url_meta":{"origin":353128,"position":5},"title":"Building a Tennis Trivia App With Next.js and Netlify","date":"October 8, 2021","format":false,"excerpt":"Today we will be learning how to build a tennis trivia app using Next.js and Netlify. This technology stack has become my go-to on many projects. It allows for rapid development and easy deployment. Without further ado let\u2019s jump in! What we're using Next.jsNetlifyTypeScriptTailwind CSS Why Next.js and Netlify You\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2021\/10\/tennis-trivia.png?fit=1200%2C632&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]}],"featured_media_src_url":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2021\/10\/Screen-Shot-2021-09-19-at-3.36.18-PM.png?fit=1024%2C561&ssl=1","_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/353128"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/286052"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=353128"}],"version-history":[{"count":10,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/353128\/revisions"}],"predecessor-version":[{"id":354583,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/353128\/revisions\/354583"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media\/353131"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=353128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/categories?post=353128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=353128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}