🥳
WindFrame Blocks is here
New Contrast Pro UI Kit and template with 5 admin dashboards, 23 pages and 10000+ components for $49 ($50 off)🎉
postImage

How to create beautiful forms using Contrast in React.

blogImage

By Emmanuel Chinonso

Web Developer

How to create beautiful sign in, sign up, newsletter contact forms in react using bootstrap and contrast.

React Bootstrap forms are input-based components which are designed to collect user data. Used as login, subscribe or contact form, all can be easily customized.

While creating CDB, we were aware of their importance in almost every project, so we have put a lot of effort to get them right.

Such constructions like predefined Form logins, Form registers, Form subscriptions or Form contacts and other layout forms varying in their design are all at your disposal. Each of them offers a different type of functionality.

We are going to look at how to create this multi-select drop-down with search today using a react library known as contrast.

Contrast also known as CDBReact is a react library which is an Elegant UI kit with full bootstrap support that has reusable components for building mobile-first, responsive websites, and web apps. To use the contact forms you need to download the pro version here.

Prerequisites

The contact forms would be built using React, Bootstrap, and CDBReact. You don’t need to have any previous knowledge of CDBReact but the following are necessary:

  • Basic React Knowledge
  • JavaScript knowledge
  • Basic Bootstrap knowledge
  • NPM installed

The page will look lke the image below

Forms

Setup

First Check that you have node installed. To do this, run the following command in your terminal.

Code

node-v

This should show you the current version of node you have installed on your machine. If you don’t have nodejs installed, download it here. Installing node also installs npm on your PC but you can still confirm using npm-v. Now that we have node installed, we can start up our React project by going to the directory of our choice and running

Code:

npx create-react-app signin-app

I named the project signin-app but you can use any name of your choice.

Install CDBReact

Now, we have to install CDBReact in our project

Run the following command to install CBDReact using NPM

npm install --save ./path-to-the-cdbreact-pro-tgz-file

Or using Yarn

yarn add ./path-to-the-cdbreact-pro-tgz-file

Note that we don’t need to install bootstrap or add it anywhere in our project as CDBReact does that for us upon installation.

Sign in

Let us go ahead to create a file named signin.js which would contain our signin component. We will be writing our code here. Import the various signin components that we’ll be using.

Code:

1import React from "react";
2import {
3 CDBInput,
4 CDBCard,
5 CDBCardBody,
6 CDBIcon,
7 CDBBtn,
8 CDBLink,
9 CDBContainer } from "cdbreact-pro";

In the code above, we imported the react from react and we also imported

  • CDBInput is used to build the input component
  • CDBCard is used to build the card structure of the sign in
  • CDBCardBody used to build the body of the sign in
  • CDBIcon is component allows you to add icons to the sign in
  • CDBBtn is the component that is used to build buttons in the sign in
  • CDBLink is the component that is used to build links for the sign in
  • CDBContainer is component holds the entire components used in building the sign in components from contrast.

Code:

1const Forms = () => {
2 return (
3 <CDBContainer>
4 <CDBCard style={{ width: "30rem" }}>
5 <CDBCardBody className="mx-4">
6 <div className="text-center mt-4 mb-2">
7 <p className="h4"> Sign in </p>
8 </div>
9 <CDBInput material hint="E-mail" type="email" />
10 <CDBInput material hint="Password" type="password" />
11 <div
12 className="d-flex flex-wrap justify-content-center align-items-center"
13 >
14 <CDBInput type="Checkbox" />
15 <p className="m-0">Remember me</p>
16 <CDBLink to="#">Forgot Password ?</CDBLink>
17 </div>
18 <CDBBtn
19 color="dark"
20 className="btn-block my-3 mx-0" >
21 Sign in
22 </CDBBtn>
23 <p className="text-center">Not a member?
24 <CDBLink className="d-inline p-0" to="#">
25 Register
26 </CDBLink>
27 </p>
28 <p className="text-center"> or sign in with</p>
29 <div className="row my-3 d-flex justify-content-center">
30 <CDBBtn
31 color="white"
32 style={{ boxShadow: "none" }}
33 >
34 <CDBIcon fab icon="facebook-f" />
35 </CDBBtn>
36 <CDBBtn
37 color="white"
38 className="m-0"
39 style={{ boxShadow: "none" }}
40 >
41 <CDBIcon fab icon="twitter" />
42 </CDBBtn>
43 <CDBBtn
44 color="white"
45 style={{ boxShadow: "none" }}
46 >
47 <CDBIcon fab icon="google-plus-g" />
48 </CDBBtn>
49 </div>
50 </CDBCardBody>
51 </CDBCard>
52 </CDBContainer>
53 );
54};
55
56export default Forms;

In the code above, we created the sign in form and included some styling in the different components in order to make them more appealing.

However, we must first render our component before we can see it display on our screen.

Code:

1import './App.css';
2import Forms from './signin';
3import Reactdom from "react-dom";
4import { BrowserRouter as Router } from 'react-router-dom';
5
6function App() {
7 return (
8 <Router>
9 <div className="App">
10 <Forms />
11 </div>
12 </Router>
13 );
14}
15
16export default App;

The final page should look like the image below

Forms

Sign up form

The sign up form is used in several web apps to register for anything or even to recognize users on a platform.

Let's go ahead to create a file named signup.js which would contain our signup component. We will be writing our code here. Import the various signup components that we’ll be using.

Code:

1import React from "react";
2import {
3 CDBInput,
4 CDBCard,
5 CDBCardBody,
6 CDBIcon,
7 CDBBtn,
8 CDBLink,
9 CDBContainer } from "cdbreact-pro";

In the code above, we imported the react from react and we also imported

  • CDBInput
  • CDBCard
  • CDBCardBody
  • CDBIcon
  • CDBBtn
  • CDBLink
  • CDBContainer components from contrast

Code:

1const Forms = () => {
2 return (
3 <CDBContainer>
4 <CDBCard style={{ width: "30rem" }}>
5 <CDBCardBody className="mx-4">
6 <div className="text-center mt-4 mb-2">
7 <p className="h4"> Sign up </p>
8 </div>
9 <div className="form-row mb-n4">
10 <div className="col">
11 <CDBInput material hint="First name" type="text" />
12 </div>
13 <div className="col">
14 <CDBInput material hint="Last name" type="text" />
15 </div>
16 </div>
17 <CDBInput material hint="E-mail" type="email" />
18 <p className="text-muted text-center small mt-n4">
19 At least 8 characters and 1 digit
20 </p>
21 <CDBInput material hint="Password" type="password" />
22 <CDBInput material hint="Phone number" type="text" />
23 <p className="text-muted text-center small mt-n4">
24 Optional - for two step authentication
25 </p>
26 <div
27 className="d-flex justify-content-center align-items-center mt-4"
28 >
29 <CDBInput type="Forms" />
30 <p className="m-0">Subscribe to our newsletter</p>
31 </div>
32 <CDBBtn
33 color="dark"
34 className="btn-block my-3 mx-0"
35 >
36 Sign up
37 </CDBBtn>
38 <p className="text-center"> or sign up with</p>
39 <div className="row mb-3 d-flex justify-content-center">
40 <CDBBtn
41 color="white"
42 className="m-0"
43 style={{boxShadow:"none"}}
44 >
45 <CDBIcon fab icon="facebook-f" />
46 </CDBBtn>
47 <CDBBtn
48 color="white"
49 className="m-0"
50 style={{boxShadow:"none"}}
51 >
52 <CDBIcon fab icon="twitter" />
53 </CDBBtn>
54 <CDBBtn
55 color="white"
56 className="m-0"
57 style={{boxShadow:"none"}}
58 >
59 <CDBIcon fab icon="google-plus-g"/>
60 </CDBBtn>
61 </div>
62 <p className="text-center m-0">
63 Already have an account?
64 <CDBLink className="d-inline p-0" to="#">
65 Sign In
66 </CDBLink>
67 </p>
68 <hr/>
69 <p className="text-center">
70 By clicking <em>Sign up</em> you agree to our
71 <CDBLink className="d-inline p-0" to="#">
72 terms of service
73 </CDBLink>
74 </p>
75 </CDBCardBody>
76 </CDBCard>
77 </CDBContainer>
78 );
79};
80
81export default Forms;

In the code above, the different components are used to create the body of the sign up contact form. We also included some styling and added social media contact in the sign up page.

The next step is to render the signup form in our app.js file.

Code:

1import './App.css';
2import Forms from './signup';
3import Reactdom from "react-dom";
4import { BrowserRouter as Router } from 'react-router-dom';
5
6function App() {
7 return (
8 <Router>
9 <div className="App">
10 <Forms />
11 </div>
12 </Router>
13 );
14}
15
16export default App;

The signup page should look like the image below.

Forms

Newsletter subscription

The newsletter subscription page will house your contact information to help business owners reach their customers and subscribers easily. The page we are going to create will look like the image below

Forms

Install CDBReact

Now, we have to install CDBReact in our project. Run the following command to install CBDReact

npm install --save cdbreact

Or using Yarn

yarn add cdbreact

Let's go ahead to create a file named newsletter.js which would contain our signup component. We will be writing our code here. First we will Import the various components that we’ll be using.

Code:

1import React from "react";
2import {
3 CDBInput,
4 CDBCard,
5 CDBCardBody,
6 CDBIcon,
7 CDBBtn,
8 CDBLink,
9 CDBContainer } from "cdbreact";

In the code above, we imported the react from react and we also imported

  • CDBInput
  • CDBCard
  • CDBCardBody
  • CDBIcon
  • CDBBtn
  • CDBLink
  • CDBContainer components from contrast

Now, we are going to write the function that will display the newsletter subscription form.

Code:

1const Forms = () => {
2 return (
3 <CDBContainer>
4 <CDBCard style={{ width: "30rem" }}>
5 <CDBCardBody className="mx-4">
6 <div className="text-center mt-4 mb-2">
7 <p className="h4">Subscribe</p>
8 </div>
9 <p className="text-center mt-4 font-weight-light">
10 Join our mailing list. We write rarely, but only the best content.
11 </p>
12 <CDBLink className="text-center p-0 font-weight-light" to="#">
13 See the last newsletter
14 </CDBLink>
15 <CDBInput material hint="Name" type="text" />
16 <CDBInput material hint="E-mail" type="email" />
17 <CDBBtn
18 color="dark"
19 className="btn-block my-3 mx-0" >
20 Subscribe
21 </CDBBtn>
22 </CDBCardBody>
23 </CDBCard>
24 </CDBContainer>
25 );
26};
27
28export default Forms;

We added some styling to the components of the newsletter contact form and links to the social media contact.

Code:

1import './App.css';
2import Forms from './newsletter';
3import Reactdom from "react-dom";
4import { BrowserRouter as Router } from 'react-router-dom';
5
6
7function App() {
8 return (
9 <Router>
10 <div className="App">
11 <Forms />
12 </div>
13 </Router>
14 );
15}
16
17Reactdom.render(<App />, document.getElementById('root'));

In the code above, we rendered the newsletter file in the app.js. This doesn’t require a pro version.

The final page will look like this

Forms

Conclusion

Contact forms are known to be used in creating sign in forms, sign up forms and newsletter which you can see is easier and much faster to create using contrast and gives you a lot of options to include bootstrap features without having to install it.

Resources

CDBReact Contact Form Docs.

Link to code on github.

Get Contrast Pro.

Create Stunning websites and web apps

Building different custom components in react for your web apps or websites can get very stressful. Thats why we decided to build contrast. We have put together a UI kit with over 10000+ components, 5 admin dashboards and 23 additional different pages template for building almost any type of web app or webpage into a single product called Contrast Pro.Try contrast pro

ad-banner

Contrast React Bootstrap PRO is a Multipurpose pro template, UI kit to build your next landing, admin, SAAS, prelaunch, etc project with a clean, well documented, well crafted template and UI components.Learn more about Contrast

Share Post:

Comments

...