[eluser]Oussama M Billah[/eluser]
here is the controller :
Code:
function index(){
$this->load->library(array('form_validation', 'session'));
// LOAD HELPERS
$this->load->helper(array('form', 'url'));
// SET VALIDATION RULES
$this->form_validation->set_message('required', 'The %s field is required. <br/>');
$this->form_validation->set_message('valid_email', 'The %s field must contain a valid email address. <br/>');
$this->form_validation->set_message('min_length', 'The %s field must be at least 6 characters in length. <br/>');
$this->form_validation->set_message('matches', 'The %s field does not match the password field. <br/>');
$this->form_validation->set_rules('userName', 'username', 'required');
$this->form_validation->set_rules('password', 'password', 'required|min_length[6]|');
$this->form_validation->set_rules('confirmPassword', 'confirm Password', 'required|matches[password]');
$this->form_validation->set_rules('firstName', 'first name', 'required');
$this->form_validation->set_rules('lastName', 'last name', 'required');
$this->form_validation->set_rules('email', 'email address', 'required|valid_email');
$this->form_validation->set_error_delimiters('<em>','</em>');
// has the form been submitted and with valid form info (not empty values)
if($this->input->post('register_x'))
{
if($this->form_validation->run())
{
$userName = $this->input->post('userName');
$user = $this->CustomerModel->getCustomer($userName);
if($user->getUserName()){
$this->session->set_flashdata('message', 'user already exists! Try again');
redirect('register');
}
$password = $this->input->post('password');
$confirmPass = $this->input->post('confirmPassword');
$fname = $this->input->post('firstName');
$lname = $this->input->post('lastName');
$email = $this->input->post('email');
$customer = new Customer();
$customer->setUserName($userName);
$customer->setPassword($password);
$customer->setFirstName($fname);
$customer->setLastName($lname);
$customer->setEmailAddress($email);
$this->CustomerModel->register($customer);
$this->session->set_userdata('user', $userName);
return redirect('products');
}
}
$this->load->view('register.php');
}
here is the form code in my view:
Code:
<div class="register_error">
<?php
$this->load->library('form_validation');
if($this->session->flashdata('message')){
echo $this->session->flashdata('message');
}
echo form_error('userName');
echo form_error('password');
echo form_error('confirmPassword');
echo form_error('firstName');
echo form_error('lastName');
echo form_error('email');
?>
</div>
<form name="register" action="register" method="post">
User Name:<br />
<input align="right" size="30" name="userName"/>
Password:<br />
<input type="password" size="30" name="password" />
Confirm Password:<br />
<input type="password" size="30" name="confirmPassword" />
First Name:<br />
<input size="30" name="firstName" />
Last Name:<span style="color:#FF0000">* </span><br />
<input size="30" name="lastName" />
Email Address:<span style="color:#FF0000">* </span><br/>
<input size="35" name="email"/>
<br />
<input type="image" name= "register" src="images/register.jpg" alt="register" width="148" height="34" /></div>
</form>
</div>