emprit

validasi CI

Nov 12th, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.04 KB | None | 0 0
  1. function user_register()
  2.     {  
  3. $this->load->library('form_validation');
  4.  
  5.  $this->form_validation->set_rules('user_name', 'Nama Lengkap', 'required');
  6.  $this->form_validation->set_rules('username', 'Username', 'required');
  7.  $this->form_validation->set_rules('pwd', 'Password', 'required|matches[cpwd]');
  8.  $this->form_validation->set_rules('cpwd', 'Password Confirmation', 'required');
  9.  $this->form_validation->set_rules('user_email', 'Email', 'required|valid_email');
  10.  $this->form_validation->set_rules('gender', 'Gender', 'required');
  11.  
  12.  if ($this->form_validation->run() == FALSE)
  13.  {
  14.  
  15.         $this->load->model('register_model');
  16.         $reg['query'] = $this->register_model->add();
  17.         if($reg['query']) {
  18.             $content['query'] = $this->home_model->lihat_home();
  19.             if($content['query']) {    
  20.                 $profile['query'] = $this->home_model->lihat_profile();
  21.                 if($profile['query']) {    
  22.                     $slide['query'] = $this->gambar_model->lihat_front();
  23.                     if($slide['query']) {  
  24.                    
  25.                     $expiration = time()-7200;
  26.                     $this->db->query("DELETE FROM captcha WHERE captcha_time < ".$expiration);
  27.                     $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
  28.                     $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration);
  29.                     $query = $this->db->query($sql, $binds);
  30.                     $row = $query->row();
  31.                        
  32.                         if ($row->count == 0){
  33.                                  $this->load->helper('captcha');
  34.  
  35.                                 $vals = array(
  36.                                         'img_path'      => './captcha/',
  37.                                         'img_url'       => 'http://lowongankerja.rifa.asia/captcha/',
  38.                                 );
  39.  
  40.                                 $cap = create_captcha($vals);
  41.                                           $time=$cap['time'];
  42.                                          
  43.                                 $data = array(
  44.                                         'captcha_time'  => $cap['time'],
  45.                                         'ip_address'    => $this->input->ip_address(),
  46.                                         'word'          => $cap['word']
  47.                                 );
  48.  
  49.                                 $query = $this->db->insert_string('captcha', $data);
  50.                                 $this->db->query($query);
  51.  
  52.                                 $isi['image'] = $cap['image'];
  53.                                
  54.                                 $array = array('home' => $this->load->view('home',$content,true),
  55.                                                     'profile' => $this->load->view('profile',$profile,true),
  56.                                                     'contact' => $this->load->view('contact', '',true),
  57.                                                     'register' => $this->load->view('register_error', $isi,true),
  58.                                                     'slide' => $this->load->view('slide',$slide,true) );
  59.                                    
  60.                               $this->load->view('index', $array);
  61.                         }else {            
  62.                        
  63.                             $array = array('home' => $this->load->view('home',$content,true),
  64.                                                 'profile' => $this->load->view('profile',$profile,true),
  65.                                                 'contact' => $this->load->view('contact', '',true),
  66.                                                 'register' => $this->load->view('register_sukses', '',true),
  67.                                                 'slide' => $this->load->view('slide',$slide,true) );
  68.                                    
  69.                             $this->load->view('index', $array);
  70.                         }   }   }   }
  71.                        
  72.         }else {
  73.             $content['query'] = $this->home_model->lihat_home();
  74.                 if($content['query']) {    
  75.                     $profile['query'] = $this->home_model->lihat_profile();
  76.                         if($profile['query']) {    
  77.                             $slide['query'] = $this->gambar_model->lihat_front();
  78.                                 if($slide['query']) {      
  79.                                     $array = array('home' => $this->load->view('home',$content,true),
  80.                                                         'profile' => $this->load->view('profile',$profile,true),
  81.                                                         'contact' => $this->load->view('contact', '',true),
  82.                                                         'register' => $this->load->view('register_gagal', '',true),
  83.                                                         'slide' => $this->load->view('slide',$slide,true) );
  84.                                    
  85.                                     $this->load->view('index', $array);  
  86.                                 }
  87.         }   }   }
  88.     }else{
  89. redirect('register');
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment