Welcome Guest, Not a member yet? Register   Sign In
Just another Recapta Library for Code Igniter 2
#1

[eluser]pukrai[/eluser]
Guys 'n gals,

I needed a Recaptcha since the built-in captcha in CI2 just does not appeal me. I put the result on github (https://github.com/pukrai/Recaptcha), have a look at it if you're interested.

The library is built on extending form_helper and form_validation, so basically is blends in really well in regular form construction/validation syntax.

View:
Code:
// the new form-tag to display the recaptcha
echo form_recaptcha();

Controller:
Code:
public function validate() {
   // load the form_validation library. Since we extended the library, we have a new
   // validation rule called 'valid_recaptcha'
   $this->load->library('form_validation');

   // new rule: valid_recaptcha, must be run on the field named 'recaptcha_challenge_field'
   $rules = array(
       array(
           'field' => 'recaptcha_challenge_field',
           'label' => 'Recaptcha',
           'rules' => 'required|valid_recaptcha',
       ),
   );

   $this->form_validation->set_rules($rules);

   if (!$this->form_validation->run()) {
       $this->load->view('welcome_message');
   } else {
       $this->load->view('recaptcha_result');
   }
}

Cheers,
puk




Theme © iAndrew 2016 - Forum software by © MyBB