Welcome Guest, Not a member yet? Register   Sign In
How is this possible?
#1

[eluser]Kristof[/eluser]
So i'm new to CI and i'm working with recaptcha i found the plugin on the codeigniter wiki. Now the plugin works just fine, but since i like to know how al things work, i'm strugling with one part.

In the configfile there is a file named form_validation.php
it contains only this:
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$config = array(
  'recaptchademo/index' => array(
    array(
      'field' => 'recaptcha_response_field',
      'label' => 'lang:recaptcha_field_name',
      'rules' => 'required|callback_check_captcha'
    )
  )
);
then the controller:
Code:
class Recaptchademo extends Controller {

    function Recaptchademo()
    {
        parent::Controller();    
    }
    
    function index()
  {
    $this->load->library('recaptcha');
    $this->load->library('form_validation');
    $this->load->helper('form');
    $this->lang->load('recaptcha');
    
   // $this->form_validation->set_rules('recaptcha_response_field', 'recaptcha_response_field', 'required|callback_check_captcha');
        
    
    if ($this->form_validation->run())
    {
      $this->load->view('recaptcha_demo',array('recaptcha'=>'Yay! You got it right!'));
    }
    else
    {
      //the desired language code string can be passed to the get_html() method
      //"en" is the default if you don't pass the parameter
      //valid codes can be found here:http://recaptcha.net/apidocs/captcha/client.html
      $this->load->view('recaptcha_demo',array('recaptcha'=>$this->recaptcha->get_html()));
    }
  }
    
    function check_captcha($val) {
      if ($this->recaptcha->check_answer($this->input->ip_address(),$this->input->post('recaptcha_challenge_field'),$val)) {
        return TRUE;
      } else {
        $this->form_validation->set_message('check_captcha',$this->lang->line('recaptcha_incorrect_response'));
        return FALSE;
      }
    }
}

Now i don't understand how it's possible that the form_validation works. If i rename the config file to test.php is does not work. But where is the form_validation loaded then? I only see the library being loaded, not that config-file?
#2

[eluser]pistolPete[/eluser]
[quote author="Kristof" date="1251651502"]... But where is the form_validation loaded then? I only see the library being loaded, not that config-file?[/quote]

Have a look at the user guide:

Quote:Saving Sets of Validation Rules to a Config File

...

Your validation rule file will be loaded automatically and used when you call the run() function.
#3

[eluser]Kristof[/eluser]
thanks that indeed answers my question. Should have looked more carefully in the usersguide, i always state my rules within the controller, well not anymoreSmile thanks again




Theme © iAndrew 2016 - Forum software by © MyBB