A dynamic form-building tool that allows users to create, customize, and validate forms seamlessly within web applications. Built with React, Next.js, and various other technologies, Form Builder provides an intuitive interface for developers and users alike.
Check out the live demo of the Form Builder here.
To get started with Form Builder, follow these steps:
Clone the repository:
git clone https://github.com/hasanharman/form-builder.git
Navigate into the project directory:
cd form-builder
Install the necessary dependencies:
npm install
To start the development server, run:
npm run dev
Open your browser and navigate to http://localhost:3000
to see the application in action.
Form Builder consists of various reusable components:
Form Builder utilizes Zod for input validation. You can define schemas for your forms as follows:
import { z } from 'zod';
const formSchema = z.object({
name: z.string().min(1, "Name is required"),
email: z.string().email("Invalid email address"),
age: z.number().min(18, "You must be at least 18 years old"),
});
This schema can be applied to your form to enforce validation rules.
Once your form is ready, you can handle submissions with a simple API call. Here’s an example of how to submit the form data:
const handleSubmit = async (data) => {
try {
const response = await fetch('/api/form-submit', {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
},
});
const result = await response.json();
console.log('Form submitted successfully:', result);
} catch (error) {
console.error('Error submitting form:', error);
}
};
Contributions are welcome! If you would like to contribute to Form Builder, please follow these steps:
git checkout -b feature/YourFeatureName
git commit -m "Add a feature"
git push origin feature/YourFeatureName
This project is licensed under the MIT License.