Created
January 15, 2012 12:08
-
-
Save phawk/1615644 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Users extends Controller { | |
function users() | |
{ | |
parent::Controller(); | |
$this->load->model('User_model'); | |
} | |
function register() | |
{ | |
// Set form validation rules | |
$this->form_validation->set_rules('first_name', 'First Name', 'required'); | |
$this->form_validation->set_rules('last_name', 'Last Name', 'required'); | |
$this->form_validation->set_rules('email', 'Email', 'required|valid_email'); | |
$this->form_validation->set_rules('pass1', 'Password', 'required|matches[pass2]'); | |
$this->form_validation->set_rules('pass2', 'Password Confirmation', 'required'); | |
if ($this->form_validation->run() == FALSE) | |
{ | |
$this->load->view('registration_form.php'); | |
} | |
else | |
{ | |
// Form validation passed, lets add the user to the database | |
// Store the inputs in an array to push to the model | |
$user_array = array( | |
'first_name' => $this->input->post('first_name'), | |
'last_name' => $this->input->post('last_name'), | |
'email' => $this->input->post('email'), | |
'password' => sha1($this->input->post('pass1')) | |
); | |
// Add the user array to the model | |
$success = $this->User_model->add_user($user_array); | |
// If the model returns true, the insert took place | |
if($success) | |
{ | |
echo 'success'; | |
} | |
else | |
{ | |
echo 'fail'; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment