<?php
class User extends Controller {
/*
Useful info
$this->input->post('postnamegoeshere') for setting postvalues from form
$this->db->like('something here') Active Record like syntax
parent::Controller(); -> things loaded here are accesible by all other functions in the controller.
*/
function Application()
{
parent::Controller();
$this->load->library('ajax');
}
function signup()
{
$this->load->library('validation');
$this->load->helper(array('form', 'url'));
$this->load->database();
$fields['username'] = 'Username';
$fields['password'] = 'Password';
$fields['passconf'] = 'Password Confirmation';
$fields['email'] = 'Email Address';
$this->validation->set_fields($fields);
if($_POST)
{
$rules['username'] = "required";
$rules['password'] = "required|matches[passconf]";
$rules['passconf'] = "required";
$rules['email'] = "required|valid_email";
$rules['type'] = "required";
$this->validation->set_rules($rules);
// Run Validation Rules, and send us somewhere
if ($this->validation->run() == FALSE)
{
$this->load->view('Signup/signup_form');
}
//Rules passed let go for the insert.
else
{
$date = date("Y-m-d H:i:s");
$password = md5($_POST['password']);
$data = array( "username" => "$_POST[username]",
"password" => "$password",
"email" => "$_POST[email]",
"type" => "$_POST[type]",
"created" => "$date");
$this->db->insert('users', $data);
$this->load->view('Signup/signup_sucess');
}
}
// No post data, give us the basic sign up form
if(!$_POST)
{
$this->load->view('Signup/signup_form');
}
}