CodeIgniter Forums
Just another Recapta Library for Code Igniter 2 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Just another Recapta Library for Code Igniter 2 (/showthread.php?tid=54328)



Just another Recapta Library for Code Igniter 2 - El Forum - 09-04-2012

[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