# Code Examples & Framework Guides Copy-ready examples for HTML, React, Next.js, Vue, Angular and plain JavaScript (Ajax), plus a prompt you can paste into your AI coding tool. ## Which framework examples are here? Every Formbold form has one endpoint, and it works with any stack. Pick your framework below, copy the example and swap in your own form ID from the **Form Setup** tab. The same snippets, with your endpoint already filled in, are on that tab too.  ## 1. Plain HTML Form The simplest way to use Formbold. Requires no JavaScript libraries or build tools: ```html
``` ## 2. Plain HTML with File Upload To accept file attachments, add enctype='multipart/form-data' to the form element: ```html ``` ## 3. Plain HTML with Google reCAPTCHA Embed the reCAPTCHA v2 widget to filter automated bots on your static form: ```html ``` ## 4. Vanilla JavaScript (AJAX / Fetch API) Submit form data asynchronously without triggering a full page reload, including loading indicators and double-submission guards: ```javascript const form = document.querySelector("#contact-form"); const submitBtn = document.querySelector("#submit-btn"); const statusMsg = document.querySelector("#status-message"); form.addEventListener("submit", async (e) => { e.preventDefault(); submitBtn.disabled = true; submitBtn.textContent = "Sending..."; const formData = new FormData(form); try { const response = await fetch("https://formbold.com/s/YOUR_FORM_ID", { method: "POST", body: formData, headers: { Accept: "application/json", }, }); if (response.ok) { statusMsg.textContent = "Thank you! Your message has been sent."; statusMsg.className = "success"; form.reset(); } else { const errorData = await response.json(); statusMsg.textContent = errorData.message || "Failed to send message."; statusMsg.className = "error"; } } catch (error) { statusMsg.textContent = "Network error. Please try again."; statusMsg.className = "error"; } finally { submitBtn.disabled = false; submitBtn.textContent = "Submit"; } }); ``` ## 5. React (Custom Component) A clean, functional React component with state management and user feedback: ```tsx import React, { useState } from "react"; export default function ContactForm() { const [status, setStatus] = useState({ state: "idle", message: "" }); const handleSubmit = async (e) => { e.preventDefault(); setStatus({ state: "loading", message: "" }); const formData = new FormData(e.target); try { const res = await fetch("https://formbold.com/s/YOUR_FORM_ID", { method: "POST", body: formData, headers: { Accept: "application/json" }, }); if (res.ok) { setStatus({ state: "success", message: "Form submitted successfully!" }); e.target.reset(); } else { setStatus({ state: "error", message: "Submission failed. Please try again." }); } } catch (err) { setStatus({ state: "error", message: "An unexpected error occurred." }); } }; return ( ); } ``` ## 6. Next.js (App Router Client Component) Next.js 14 / 15 / 16 compatible App Router component with client-side form submission: ```tsx "use client"; import { useState } from "react"; export default function NextContactForm() { const [submitting, setSubmitting] = useState(false); const [submitted, setSubmitted] = useState(false); const onSubmit = async (e: React.FormEventYour message has been received. We will get back to you shortly.