• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validasi Captcha di form register tidak berhasil saat validasi TRUE

#1
hello master2 selamat sore,

saya baru belajar CI , dan membuat form registrasi sederhana mengikuti beberapa documentasi dari CI dan tutorial dari beberapa blog. Tapi ada error saat validasi sukses captcha. Saat validasi captcha nya false(tidak sesuai) maka pesan error ditampilkan , dan ini berhasil. Akan tetapi justru error saat validasi true, dimana seharusnya langsung insert data ke database tapi ini stuck. Mohon bantuannya dan bimbingannya. Terimakasih sebelumnya


dan ini controller saya (Register.php):
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Register extends CI_Controller {

    public function index() {
         $this->load->library(array('form_validation'));
         $this->load->library('image_lib');
        $this->load->helper(array('url','form'));
         $this->load->helper('captcha');
        $this->load->model('m_account'); //call model
        $this->form_validation->set_rules('username', 'USERNAME','required');
        $this->form_validation->set_rules('email','EMAIL','required|valid_email');
        $this->form_validation->set_rules('password','PASSWORD','required');
        $this->form_validation->set_rules('password_conf','PASSWORD','required|matches[password]');
         $this->form_validation->set_rules('captcha', 'CAPTCHA', 'required');
         $this->form_validation->set_rules('userCaptcha', 'Captcha', 'required|callback_check_captcha');
         $userCaptcha = $this->input->post('userCaptcha');
        
        if($this->form_validation->run() == FALSE) {
            //random number
            $random_number = substr(number_format(time() * rand(),0,'',''),0,6);
            //setting captcha config
            $vals = array(
                'word' => $random_number,
                'img_path' => './static/',
                'img_url' => base_url().'static/',
                'img_width' => 140,
                'img_height' => 32,
                'expiration' => 7200
                );
            $data['captcha'] = create_captcha($vals);
            $this->session->set_userdata('captchaWord',$data['captcha']['word']);
            $this->load->view('reader');
           $this->load->view('account/register',$data);
            $this->load->view('footer');
            
        }else{
             $this->session->unset_userdata('captchaWord');            
            $data['username'] =    $this->input->post('username');
            $data['email']  =    $this->input->post('email');
            $data['password'] =    md5($this->input->post('password'));
            $this->m_account->daftar($data);
            $pesan['message'] =    "Pendaftaran berhasil anda berhasil silahkan login";
            $this->load->view('reader');
            $this->load->view('account/sukses',$pesan);
             $this->load->view('footer');
         }
     }
     public function check_captcha($str){
        $word = $this->session->userdata('captchaWord');
        if(strcmp(strtoupper($str),strtoupper($word)) == 0){
            return true;
        }
        else{
            $this->form_validation->set_message('check_captcha', 'Please enter correct words!');
            return false;
        }
    }
}

Dan ini model nya (M_account.php):

Code:
<?php
 defined('BASEPATH') OR exit('No direct script access allowed');

 class M_account extends CI_Model{

      function daftar($data)
      {
           $this->db->insert('tb_users',$data);
      }
 }

dan ini viewnya (Register.php)
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>

    <div id="content">
    <h2>Pendaftaran Member Baru</h2>

    <?php echo form_open('register');?>
 <form id="formdaftarins" action="<?php echo base_url()?>register" method="post">  
<div id=form_wrapper>
<div class=form_title>Form Pendaftaran</div>
    <div class=form_label>Username</div>
    <div class=form_value><input type="text" maxlength="15" id="user" name="username" class="form_input" autocomplete="off" width="50" value="<?php echo set_value('username'); ?>"/> </div>
    <p> <?php echo form_error('username'); ?> </p>
     <div class=form_label>Email:</div>
    <div class=form_value><input type="email" maxlength="100" name="email" id="email" class="form_input" autocomplete="off" value="<?php echo set_value('email'); ?>"/></div>
    <p> <?php echo form_error('email'); ?> </p>
    <div class=form_label>Password:</div>
    <div class=form_value><input type="password" id="pass" maxlength="15" name="password" class="form_input" autocomplete="off" value="<?php echo set_value('password'); ?>"/></div>
    <p> <?php echo form_error('password'); ?> </p>
    <div class=form_label>Password Confirm:</div>
    <div class=form_value><input type="password" id="pass" maxlength="15" name="password_conf" class="form_input" autocomplete="off"  value="<?php echo set_value('password_conf'); ?>"/></div>
    <p> <?php echo form_error('password_conf'); ?> </p>
    
    <p>
    <label for="captcha"><?php echo $captcha['image']; ?></label>
    <input type="text" autocomplete="off" name="userCaptcha" placeholder="Enter above text" value="<?php if(!empty($userCaptcha)){ echo $userCaptcha;} ?>" />
   <span class="required-server"><?php echo form_error('userCaptcha','<p style="color:#F83A18">','</p>'); ?></span>
    <p>
    <input type="submit" name="btnSubmit" value="Daftar" />
    
    </p>
</div>
    </form>
    <?php echo form_close();?>
</div>
   
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
2 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.