FormBotJS dynamically creates a chat-style form inside any container using simple configuration and HTML attributes. No need for external libraries — lightweight, flexible, and developer-friendly.
Try the DemoThis form is only for demonstration purposes; we don't collect any data as the endpoint is just for testing.
Add FormBotJS to your project in just 3 simple steps. Include the CDN links, create a container, and initialize the bot with your form questions.
See the Pen form_boat_demo by Firoz (@LearnWithFiroz) on CodePen.
Each item in questions is a single step in the conversational form.
It closely mirrors an HTML input: label, name, type,
attrs (HTML-like attributes) and optional options.
type valuestext, email, number, date, file, textareaselect (single), multiselect (multiple select)radio, checkbox (multiple choice)hidden (Won’t be displayed to the user but will be included in the answers object and
submitted to the endpoint, similar to extraData.)message (display-only bot message)attrs for validation & hintsPut HTML attributes here (they get applied to the generated input):
required, minlength, maxlengthpattern, placeholder, titlemin, max, step (for numbers/dates)accept (file types), data-maxsize (file size MB)--chat_color1)"submit" to POST, "return" to skip network(answers, formData) when finished// simple text + select + file example
const questions = [
{
label: "What's your full name?",
name: "name",
type: "text",
attrs: { required: true, minlength: 3, placeholder: "e.g., Raju Kumar" }
},
{
label: "Who are you?",
name: "role",
type: "select",
options: ["Student", "Teacher"],
attrs: { required: true }
},
{
label: "Which subjects are you interested in?",
name: "subjects",
type: "multiselect",
options: ["Math","Science","English"],
attrs: { required: true }
},
{
label: "Upload a profile photo (max 2MB)",
name: "photo",
type: "file",
attrs: { accept: "image/*", "data-maxsize": "2" }
},
// display-only final message (optional)
{
label: "Thanks! We'll contact you soon.",
name: "end_message",
type: "message"
}
];
// initialize FormBot
FormBot.init({
chat_containerId: "chat-form-container", // required
post_url: "/api/submit", // server endpoint (used when mode === "submit")
color1: "#28a745", // primary color (updates CSS var)
mode: "submit", // "submit" or "return"
extraData: { _token: "CSRF_TOKEN_HERE" }, // appended to FormData
showProgress: true,
saveToLocalStorage: true,
questions, // pass the questions array
onComplete: (answers, formData) => {
// answers = [{name, label, value, file?}, ...]
// formData = FormData instance (useful if you want to send it yourself)
console.log("collected:", answers);
}
});
Tip: put all HTML attributes inside attrs. That keeps the question definition compact and
predictable.