Codeigniter is one of the best MVC frameworks in PHP, creating a project in Codeigniter framework is simple, when compared to other frameworks called Yii framework and laravel framework.
If we plan to create a project, the first thing we need to create Codeigniter user registration form, in every project when it moves to development stage, first thing we create registration page to get leads.

We all know Codeigniter is MVC Framework which stands for Model, Veiw and controller. So now you understand what files we need, let’s jump into the Codeigniter user registration form.
First we need to create view for registration page , which display in frontend. Let’s create view as registration.php under view folder. If you have good knowledge in HTML and CSS you can design your view using bootstrap, which looks beautiful and mobile friendly. Now I am sharing registration.php file which I created for this demo.

<script  type="text/javascript" src="<?php echo base_url();?>js/jquery.min.js"></script>
<script  type="text/javascript" src="<?php echo base_url();?>js/uservalidation.js"></script>
<h5 class="head">Codeigniter User Registration </h5>
<div class="d-form bdr mgn0">
<div class=""> 
</div>

<div>
<form method="post" action="insertnewuser" id="form" >
<div class="white-shadow content-inner-block">
	<span style="font-weight:normal;color:#333333;text-align:right">
		<font color="red">*</font> Marked fields are compulsory
	</span>
	</div>
	<div class="form-group">
    <label for="txtLoginid">Name <span class="style1">*</span> </label>
     <input name="txtName" type="text" size="25" id="txtName" placeholder="First Name" class="form-control" value="<?php echo set_value('txtName');?>" />
     <span id="nameError" class="red"></span>
     <span style="color:red"><?php //echo form_error('txtName');?></span>
     </div>
		<div class="form-group">
    <label for="txtLoginid">Email <span class="style1">*</span> </label>
     <input name="txtEmail" type="email" size="25" id="txtEmail" placeholder="Enter email" class="form-control" value="<?php echo set_value('txtEmail');?>" />
     <span id="emailError" class="red"></span>
     <span style="color:red"><?php echo form_error('txtEmail');?></span>
     </div>
     <div class="form-group">
    <label for="txtEmailConf">Confirm Email <span class="style1">*</span></label>
     <input name="txtEmailConf" type="email" size="25" id="txtcompanyname" placeholder="Confirm email" class="form-control" value="<?php echo set_value('txtEmailConf');?>" />
     <span id="verifyemailerror" class="red"></span>
          <span style="color:red"><?php echo form_error('txtEmailConf');?></span>
     </div>
   <div class="radio">
    <label>
   <input type="radio" id="individual" name="usertype" value="user">Individual
    </label></div>
    <div class="radio">
     <label>
<input type="radio" id="dealerdisplay" name="usertype"  value="dealer">Dealer
    </label>
    <span style="color:red"><?php echo form_error('usertype');?></span>
     <span id="usertypeError" class="red"></span>
  </div>
		
        <div class="form-group">
    <label for="txtcompanyname">Company Name</label>
     <input name="txtcompanyname" type="text" size="25" id="txtcompanyname" placeholder="Enter Company name" class="form-control" value="<?php echo set_value('txtcompanyname');?>" />
     </div>
      <div class="form-group">
    <label for="txtPassword">Create a Password <span class="style1">*</span></label>
     <input name="txtPassword" type="password" size="25" id="txtPassword" placeholder="Enter password" class="form-control" value="<?php echo set_value('txtPassword');?>" />
          <span style="color:red"><?php echo form_error('txtPassword');?></span>
<span id="passwordError" class="red"></span>
     </div>
          <div class="form-group">
    <label for="txtConfirmPassword">Confirm your Password <span class="style1">*</span></span></label>
     <input name="txtConfirmPassword" type="password" size="25" id="txtConfirmPassword" placeholder="Confrim password" class="form-control" value="<?php echo set_value('txtConfirmPassword');?>" />
               <span style="color:red"><?php echo form_error('txtConfirmPassword');?></span>
               <span id="pwVerifiedError" class="red"></span>

     </div>
      <div class="form-group">
    <label for="txtMobile">Mobile No. <span class="style1">*</span></label>
     <input name="txtMobile" type="text" size="25" id="txtMobile" maxlength="10" class="form-control" value="<?php echo set_value('txtMobile');?>" />
     <span style="color:red"><?php echo form_error('txtMobile');?></span>
     </div>
      <div class="form-group">
    <label for="txtcity">City Name <span class="style1">*</span></label>
     <input name="txtcity" type="text" size="25" id="txtcity" maxlength="10" class="form-control" value="<?php echo set_value('txtcity');?>" />
      <span style="color:red"><?php echo form_error('txtcity');?></span>
       <span id="cityError" class="red"></span>
     </div>
     
     <div class="checkbox">
    <label>
     <input id="checkbox" type="checkbox" name="checkbox" onclick="if(!this.form.checkbox.checked){alert('You must agree to the terms first.');return false}"/> I have read and agree with the <a target="_blank" href="<?php echo base_url();?>user/autofliq_terms">User Agreement and Privacy Policy</a> 
    </label>
  </div>
   <button type="submit" class="btn btn-default" name="btnRegister">Submit</button>
</form>
</div>
</div>

Now in the above code we simple created html form using Div’s, and also we added php tags , here

<?php      code here .. ?>

Which is php opening and closing braces in between we can write our php code, here you find two major php code i.e.
1) set_value(); which helps you to set value to the field
2) form_error(); which show form error, when value is missing or wrong typo.
Now let’s move to controller file , let’s create controller name as user.php and create function as below.

public function insertnewuser()
	{   
	               $this->load->library('form_validation');
		 $this->form_validation->set_rules('txtEmail','email','required|valid_email|is_unique[autoflip_user.emailid]|xss_clean|trim');
		 $this->form_validation->set_rules('txtEmailConf','Email Confirmation', 'required|matches[txtEmail]|xss_clean|trim');
		 $this->form_validation->set_rules('usertype', 'Radio button', 'required');
		 $this->form_validation->set_rules('txtcity', 'city', 'required|min_length[5]|max_length[12]|xss_clean|trim');
		 $this->form_validation->set_rules('txtPassword','Password','required|xss_clean|trim');
		 $this->form_validation->set_rules('txtConfirmPassword','Password Confirmation', 'required|matches[txtPassword]|xss_clean|trim');
		if ($this->form_validation->run() == FALSE)
			{
	
				$this->settemplate->usertemp('user/userregistration');
	 
			}
			else
			{
		
		   $insertdata=$this->user_service->insertuserrecord();
		   //$send_mail=$this->user_service->send_mail();
			
			  if($insertdata)
			  {
			    $mobile=$this->input->post("txtMobile");   
				$msg="DEAR ".$this->input->post('txtName').", Thanks for Registering with AutofliQ.Com, your account is now activated and ready for using. Visit WWW.AutofliQ.com for more services";
               $this->smsRegdSend($mobile,$msg);
			    $sender_mail = '[email protected]';
				$mail=$this->input->post('txtEmail');
				$data['firstname']=$this->input->post('txtName');
				$this->load->library('email');
				$config = array(
						  'mailtype' => 'html',
						  'charset'  => 'utf-8',
						  'priority' => '1'
						   );
				$this->email->initialize($config);
				$this->email->from($sender_mail,'AutofliQ');
				$this->email->to($mail);
				$this->email->cc('[email protected]'); 
				$this->email->subject('Welcome To AutofliQ');
				$message=$this->load->view('user/map_mail_format',$data,TRUE);
				$this->email->message($message);
				$this->email->send();     

			    $this->session->set_flashdata('message','Registration successful,Please Enter Your Login Details Below');
			    $this->settemplate->usertemp('user/userlogin',$message);
			  }
		   }
	}

Don’t understand above code? Ok then let’s debug each and every line, after creating the function, first you need to load required libraries for your validations and email.
• For better validation, Codeigniter have inbuilt library for validation and also provide some decent features to restrict cross site scripting.
• You can see syntax for validation as

 $this->form_validation->set_rules();

Now your validation filed looks as below.
codeigniter user registration form
If your inputs are wrong it will move to your view registration.php and again you need to enter the valid values. Now if the values you entered are all valid your data will move to model function which looks like below.

 $insertdata=$this->user_service->insertuserrecord();

And once your data moved to model function insertuserrecord(), the insert code looks like below.

public function insertuserrecord()
				 {
					  $this->load->helper('string');
					  $name=$this->input->post('txtName', TRUE);
					  $email=$this->input->post('txtEmail', TRUE);
					  $usertype=$this->input->post('usertype',TRUE);
					  $companyname=$this->input->post('txtcompanyname',TRUE);
					  $password=$this->input->post('txtPassword',true);
					  $pass_key=md5($this->input->post('txtPassword',TRUE));
					  $Mobilenumber=$this->input->post('txtMobile',TRUE);
					  $city=$this->input->post('txtcity',TRUE);
					  $key=random_string('alnum',5);
					  $insertStatus=$this->db->insert('autoflip_user',array('firstName'=>$name ,'emailid'=>$email,'usertype'=>$usertype,'company_name'=>$companyname,'password'=>$password, 'pass_key'=>$key,'pass_encryption'=>$pass_key ,'mobilenumber'=>$Mobilenumber,'city'=> $city));
					  return $insertStatus;
				}

After inserting data to database, we simply return $insertStatus; variable to controller again. Now let’s move to controller again and write code for email notification after successful user registration, let’s check how code looks in controller.

$this->load->library('email');
				$config = array(
						  'mailtype' => 'html',
						  'charset'  => 'utf-8',
						  'priority' => '1'
						   );
				$this->email->initialize($config);
				$this->email->from($sender_mail,'AutofliQ');
				$this->email->to($mail);
				$this->email->cc('[email protected]'); 
				$this->email->subject('Welcome To AutofliQ');
				$message=$this->load->view('user/map_mail_format',$data,TRUE);
				$this->email->message($message);
				$this->email->send();     

In this code we simply calling inbuilt email library from Codeigniter core files and initialize email , for every email , we have From, To ,CC , SUBJECT, BODY .
In the same format we have functions in the email library, just we need to pass the parameters to send email notifications to registered user.