Advertisement
Guest User

Untitled

a guest
May 12th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. <?php
  2.  
  3. function debug($v)
  4. {
  5.     echo '<pre>'; print_r($v); echo '</pre>';
  6. }
  7.  
  8. class Signup extends Controller {
  9.    
  10.     public function __construct() {
  11.         parent::Controller();
  12.        
  13.         $this->load->helper(array('form','url'));
  14.         $this->load->library('form_validation');
  15.     }
  16.    
  17.     public function index() {
  18.         $this->load->view('signup_form');
  19.     }
  20.    
  21.     public function submit()
  22.     {
  23.         if ($this->_submit_validate() === FALSE)
  24.         {
  25.             $this->index();
  26.             return;
  27.         }
  28.  
  29.         $u = new User();
  30.         $u->username = $this->input->post('username');
  31.         $u->password = $this->input->post('password');
  32.         $u->email = $this->input->post('email');
  33.         $u->save();
  34.        
  35.         $this->load->view('submit_success');
  36.    
  37.     }
  38.    
  39.     private function _submit_validate() {
  40.        
  41.         // validation rules
  42.         $this->form_validation->set_rules('username', 'Username',
  43.             'required|alpha_numeric|min_length[6]|max_length[12]|unique[User.username]');
  44.        
  45.         $this->form_validation->set_rules('password', 'Password',
  46.             'required|min_length[6]|max_length[12]');
  47.        
  48.         $this->form_validation->set_rules('passconf', 'Confirm Password',
  49.             'required|matches[password]');
  50.        
  51.         $this->form_validation->set_rules('email', 'E-mail',
  52.             'required|valid_email|unique[User.email]');
  53.        
  54.         return $this->form_validation->run();
  55.        
  56.     }
  57.    
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement