CREATE TABLE IF NOT EXISTS `clist` (
`sno` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(55) NOT NULL,
`email` varchar(55) NOT NULL,
`password` varchar(55) NOT NULL,
`city` varchar(55) NOT NULL,
`status` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`sno`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
autoload.php :
We have to change in autoload.php as follows,
$autoload['libraries'] = array('database','form_validation','uri');
$autoload['helper'] = array('html', 'form', 'url');
register_view.php
<style type="text/css">
table {
background:#ADDAF1;
border-radius:10px;
margin-top:95px;
}
</style>
<title><?php echo $title;?></title>
<form action="<?=base_url()?>Register/insert" name="form1" id="form1" method="post" >
<table width="200" border="0" align="center">
<tr>
<td>Name:</td>
<td><input type="text" name="name" id="name"> <font color="#FF0000"><?php echo form_error('name');?></font></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" id="email"> <font color="#FF0000"><?php echo form_error('email');?></font></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" id="password"> <font color="#FF0000"><?php echo form_error('password');?></font></td>
</tr>
<tr>
<td>City:</td>
<td><select name="city" id="city">
<option value="">Select</option>
<option value="bangalore">bangalore</option>
<option value="vijayawada">vijayawada</option>
</select> <font color="#FF0000"><?php echo form_error('city');?></font></td>
</tr>
<tr><td colspan="2" align="center"><input type="submit" name="submit" id="submit" value="Register"></td></tr>
</table>
</form>
<script src="<?=base_url()?>/assets/js/jquery-1.11.3.min.js"></script>
<script src="<?=base_url()?>/assets/js/bootstrap.min.js"></script>
<script src="<?=base_url()?>/assets/js/jquery.validate.min.js"></script>
<script src="<?=base_url()?>/assets/js/jquery-ui.js"></script>
<script>
$(function() {
});
(function($,W,D)
{
var JQUERY4U = {};
JQUERY4U.UTIL =
{
setupFormValidation: function()
{
$("#form1").validate({
rules: {
name: {
required: true ,
minlength:2
},
email: {
required: true,
email:true
},
password: {
required: true,
minlength:4,
maxlength:10
}
},
messages: {
name: {
required:"<font color='red'>Please Enter Name</font>",
minlength:"<font color='red'>Minimum length is 2</font>"
},
email: {
required:"<font color='red'>Please Enter Email Id</font>",
email:"<font color='red'>Please Enter Valid Email Id</font>"
},
password: {
required:"<font color='red'>Please Enter Password </font>",
minlength:"<font color='red'>Minimum length is 4 </font>",
maxlength:"<font color='red'>Maximum length is 10 </font>"
}
},
submitHandler: function(form) {
form.submit();
}
});
}
}
//when the dom has loaded setup form validation rules
$(D).ready(function($) {
JQUERY4U.UTIL.setupFormValidation();
});
})(jQuery, window, document);
</script>
Register.php(Controller)
<?php
ob_start();
class Register extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model("Register_model");
}
public function index()
{
$this->insert();
}
public function insert()
{
$this->form_validation->set_rules('name', 'Name', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('password', 'Password', 'required|numeric');
$this->form_validation->set_rules('city','City','required');
if ($this->form_validation->run())
{
$register=$this->Register_model->insertdata($_POST);
if($register){
$this->Register_model->Send_Email($this->input->post('email'));
echo "<script>alert('Please check Your Email To Activate Account...')</script>";
}
}
$data['title']="Registration";
$this->load->view('register_view',$data);
}
function verify($hash=NULL)
{
if ($this->Register_model->verifyEmailID($hash))
{
echo "<script>alert('Account Activated...')</script>";
}
else
{
echo "<script>alert('Sorry Something Went Wrong...')</script>";
}
}
}
?>
Register_model.php(Model)
<?php
class Register_model extends CI_Model {
function insertdata($options = array()){
if(isset($options['name']))
$this->db->set('name',strip_tags($options['name']));
if(isset($options['email']))
$this->db->set('email',strip_tags($options['email']));
if(isset($options['password']))
$this->db->set('password',strip_tags($options['password']));
if(isset($options['city']))
$this->db->set('city',($options['city']));
$this->db->insert("clist");
return $this->db->insert_id();
}
public function Send_Email($to_email) {
$message = 'Hi,<br /><br />Please Verify http://www.domain.com/Register/verify/' . md5($to_email) . '<br /><br /><br />Thanks<br />Mydomain Team';
$this->load->library('email');
$this->email->from('fromemail@gmail.com', 'Codetipz');
$this->email->to($to_email);
$this->email->subject('Email Verification');
$this->email->message($message);
$this->email->send();
}
//activate user account
function verifyEmailID($key)
{
$data = array('status' => 1);
$this->db->where('md5(email)', $key);
return $this->db->update('clist', $data);
}
}
?>
04:22
Share:
0 comments: