Codeigniter Simple Registration System
![]() |
| Codeigniter Simple Registration System |
Hi Guys today we are going to learn Simple Registration system in Codeigniter .
Just Follow the Codeigniter simple registration example..
Configuration:
application/config/autoload.php
$autoload['helper'] = array('url');
application/config/config.php
$config['base_url'] = 'http://localhost/codeigniter/';
Controllers:
application/controllers/blog.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Blog extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper('email');
$this->load->library('form_validation');
}
public function index()
{
$this->load->view('index');
}
public function registration(){
//Validating Form
$this->form_validation->set_rules('username','UserName','trim|required|min_length[6]|max_length[12]');
$this->form_validation->set_rules('password','Password','trim|required');
$this->form_validation->set_rules('passconf','Confirmation Password','trim|required|matches[password]');
$this->form_validation->set_rules('email','Email','trim|required|valid_email');
$this->form_validation->set_rules('fname','First Name','trim|required');
$this->form_validation->set_rules('lname','First Name','trim|required');
if($this->form_validation->run() == FALSE){
$this->load->view('index');
}else{
$data = array(
'username' => $this->input->post('username'),
'password' => $this->input->post('password'),
'passconf' => $this->input->post('passconf'),
'email' => $this->input->post('email'),
'fname' => $this->input->post('fname'),
'lname' => $this->input->post('lname')
);
//Loading Model
$this->load->model('Reg_model');
$data['result']=$this->Reg_model->regsuccess($data);
//Send Success Message
$data['message']='Registration Successfully Completed';
$this->load->view('index',$data);
}
}
}
?>
Model:application/models/reg_model.php
<?php
class Reg_model extends CI_model{
public function regsuccess($data){
$this->load->database();
$query=$this->db->insert('user', $data);
}
}
?>
Views:
<style>
.error{
color:red;
font-weight:bold;
font-style:italic;
}
input[type=text]{
padding:5px;
border-radius:4px;
}
input[type=submit]{
padding:7px;
background:black;
color:white;
border-radius:4px;
}
</style>
<h2>Codeigniter Registration System</h2>
<form method="POST" action="<?php echo base_url();?>index.php/blog/registration">
<table>
<tr>
<td>UserName:</td>
<td><input type="text" name="username"/>
<?php echo form_error('username','<div class=error>','</div>');?>
</td>
</tr>
<tr>
<td>Password:</td>
<td><input type="text" name="password"/>
<?php echo form_error('password','<div class=error>','</div>');?>
</td>
</tr>
<tr>
<td>Confirm Password:</td>
<td><input type="text" name="passconf"/>
<?php echo form_error('passconf','<div class=error>','</div>');?>
</td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email"/>
<?php echo form_error('email','<div class=error>','</div>');?>
</td>
</tr>
<tr>
<td>First Name:</td>
<td><input type="text" name="fname"/>
<?php echo form_error('fname','<div class=error>','</div>');?>
</td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="lname"/>
<?php echo form_error('lname','<div class=error>','</div>');?>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Sign Up"/></td>
</tr>
</table>
</form>
<?php
if(isset($message)){
echo $message;
}
?>
run http://localhost/codeigniter/index.php/blog and enjoy.
That's it how to create simple Registration form in Codeigniter.. Keep Visiting this blog for more codes and don't forget to leave your Comment..Thank You.


No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.