Skip to content

Instantly share code, notes, and snippets.

@phawk
Created January 15, 2012 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phawk/1615644 to your computer and use it in GitHub Desktop.
Save phawk/1615644 to your computer and use it in GitHub Desktop.
<?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