Input field
1. Add the HTML form
Ensure your HTML form includes the surface-form-handler class. This class is essential for identifying the form as one that triggers the Surface Form popup. Example:
<form class="surface-form-handler">
<input type="email" placeholder="Enter your email" required />
<button type="submit">Submit</button>
</form>
2. Surface form constructor
Add the following code to the app/layout.tsx file:
import Script from "next/script";
export default function RootLayout({
children,
}: {
children: React.ReactNode,
}) {
return (
<html lang="en">
<head>
<Script
src="https://cdn.jsdelivr.net/gh/trysurface/scripts@latest/surface_tag.min.js"
data-site-id="SITE_ID"
strategy="beforeInteractive"
/>
<Script
strategy="afterInteractive"
id="surface-form-script"
data-question-id="<question_id>"
dangerouslySetInnerHTML={{
__html: `
(function () {
const surface_src = "REPLACE ME WITH FORM URL"
const surface_embed_type = "popup"
const target_element_class = "surface-form-button"
const c = new SurfaceEmbed(surface_src, surface_embed_type, target_element_class)
})();
`,
}}
/>
</head>
<body>{children}</body>
</html>
);
}