Create simple form in 5 minutes⏱ (Medium article)
Currently available
- Contact form
- (Up comming) Pre register form
- (Up comming) Feedback form
npm i @kazuwombat/fire-form
or
yarn add @kazuwombat/fire-form
- Setup FirebaseProject for Web. Detail here
- When you setup Firebase project, you can get Firebase Config like below. Copy it for when you implement the form.
- Create Firebase Real Time Database. Detail here
- Update database rule with below.
{
"rules": {
".read": false,
".write": true
}
}
- Create firebaseConfig.ts file with config which you copied while Firebase project setup.
export default {
apiKey: "xxxxxxx",
authDomain: "xxxxxxx",
databaseURL: "xxxxxxx",
projectId: "xxxxxxx",
storageBucket: "xxxxxxx",
messagingSenderId: "xxxxxxx",
appId: "xxxxxxx",
measurementId: "xxxxxxx"
};
- Then make contact form with the config. You need to handle success(for example show thank you modal) and error callbacks.
import React from "react"
import { ContactForm } from '@kazuwombat/fire-form'
import config from '../firebaseConfig'
const ContactPage = () => {
return (
<ContactForm
config={config}
successCallback={() => { alert("success :)") /* TODO Handle Success */
}}
errorCallback={(error) => {alert(error) /* TODO Handle Error */
}}
/>
)
}
export default ContactPage
Yay 🎊 you’ve completed to create contact form 👍
Let’s test submitting form.
Then check firebase have saved the data successfully.
ContactForm accept setting object below.
export interface ContactFormSetting {
containerStyle?: CSS.Properties;
formStyle?: CSS.Properties;
textStyle?: CSS.Properties;
textAreaStyle?: CSS.Properties;
buttonStyle?: CSS.Properties;
indicatorStyle?: CSS.Properties;
namePlaceHolder?: string;
companyNamePlaceHolder?: string;
emailPlaceHolder?: string;
contentPlaceHolder?: string;
submitButtonLabel?: string;
}
You can customize form visual pass config object to Contactform.
<ContactForm
config={config}
setting={{
formStyle: {
backgroundColor: "green"
}
}}
successCallback={() => {
alert("success :)") /* TODO Handle Success */
}}
errorCallback={(error) => {
alert(error) /* TODO Handle Error */
}}
/>
See another repo, fire-form-functions