# 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. ![Form Setup Code Examples](#) ## 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 (
``` ## 8. Angular (standalone component) An Angular standalone component that posts with `HttpClient`. Add `provideHttpClient()` to your app config if you haven't already. ```typescript import { Component, inject } from "@angular/core"; import { HttpClient } from "@angular/common/http"; @Component({ selector: "app-contact-form", standalone: true, template: `

{{ status }}

`, }) export class ContactFormComponent { private http = inject(HttpClient); sending = false; status = ""; onSubmit(event: Event) { event.preventDefault(); const form = event.target as HTMLFormElement; this.sending = true; this.http .post("https://formbold.com/s/YOUR_FORM_ID", new FormData(form), { headers: { Accept: "application/json" }, }) .subscribe({ next: () => { this.status = "Thanks! Your message has been sent."; form.reset(); this.sending = false; }, error: () => { this.status = "Something went wrong. Please try again."; this.sending = false; }, }); } } ``` If you use `*ngIf`, import `NgIf` (or `CommonModule`) in the component's `imports`. On Angular 17 and newer you can use `@if` instead. ## 9. Prompt for AI coding tools The quickest route is the **Built with an AI Tool?** section on your form's **Form Setup** tab. Pick Lovable, Bolt.new, v0.dev, Cursor, ChatGPT or General, and Formbold writes the prompt with your endpoint already in it. If you'd rather write your own, this one works in Cursor, ChatGPT, Claude or v0: ```markdown I have created a Formbold form with the endpoint: https://formbold.com/s/YOUR_FORM_ID Please help me integrate this form into my web application. My stack is: [Insert stack, e.g. Next.js 15 App Router with Tailwind CSS] Requirements: 1. Submit the form to the Formbold endpoint using POST. 2. Provide form fields for Name, Email, and Message with proper validation. 3. Use the Fetch API with an 'Accept: application/json' header, so the page doesn't reload. 4. Disable the submit button and show a spinner while submitting. 5. Display accessible success and error state alerts. 6. Reset the form fields after successful submission. ``` Read what the AI gives back before you ship it. Check the URL is your endpoint and every field still has a `name`.