How to create registration form in Codeigniter

Codeigniter is one of the most popular PHP MVC framework available right now. It comes with bunch of built-in libraries and helper functions like database, form validation, session, form helper, database helper, shopping cart library. Codeigniter is not like another PHP framework in which you have to adjust some system configurations or install some dependencies. You just need to download codeigniter set base path, enter database credentials and you are good to go.

So in this tutorial I am going to show you how to create registration form in codeigniter. This tutorial is for the beginner so I am not going to cover email verification after registration. I will just cover registration form in very simple manner. I will cover email verification in my coming tutorials.

In this tutorial I am not going to cover codeigniter installation. If you are new to codeigniter then please read How to install Codeigniter in Xampp first or if your not familiar with codeigniter directory structure then visit Codeigniter Framework Directory Structure.


Steps involved in creating registration form in Codeigniter

  • Create registration form
  • Submit registration form and validate form fields.
  • Check if user is new or already exists.
  • If user is new insert user information into database and redirect user to thankyou page.
  • If for any reason user information will not savethen through an error.

Create Database:

Create database Table:

Codeigniter Setting:

  • Setup base path in config/config.php
  • Add database credentials in config/database.php
  • Autoload database library in config/autoload.php like $autoload['libraries'] = array('database');
  • Autoload url helper in config/autoload.php like $autoload['helper'] = array('url');
  • Add user as default controller in config/routes.php

Create Controller:

Users.php

Users.php is a controller file in controllers folder that has 4 functions which are:

  • __construct() : calls parent constructer
  • Index(): load register form
  • RegisterUser(): save register form data
  • Thankyou(): display thankyou page

Create Model:

User_model.php

User_model.php is model file in models folder that has 3 functions which are:

  • __construct(): calls parent construct.
  • checkDuplicate(): check email is new or already in the table.
  • insertUser(): insert user information into the table.

Create Views:

Register.php

  • Using bootstrap css and jquery link.
  • validation_errors() is used to print form validation errors.
  • $errorMsg is used to print duplicate email and unable to save errors
  • Form will be post on RegisterUser function
  • set_value() function is used to print post value in the input field.

Thankyou.php

Just print thank you message after insertion.

 

Leave a Reply

Your email address will not be published. Required fields are marked *