CodeIgniter Forums
how to validate a recaptcha plugin using a controller? - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: how to validate a recaptcha plugin using a controller? (/thread-56837.html)

how to validate a recaptcha plugin using a controller? - El Forum - 01-24-2013

hi guys i have a little problem. My problem is i used a captcha api named recaptcha and i have a problem in validating my form. I have no problem in viewing but the validation doesn't work.
Please help me guys

here's a bit of code in my view together with the capctha:

<?php $attr = array('name'=>'member', 'id' => 'formID'); ?>
<?php echo form_open('payment_controller/addToMember',$attr); ?>
  <div class="membership_form_box">
                <li><label>Desired Username* (max of 10 characters)</label>&lt;input type="text" name="username" tabindex="16"  alpha(event)" value="&lt;?php echo set_value('username'); ?&gt;" placeholder="" size="30"  maxlength="16" class="input_item03"/&gt;&lt;/li>
                <li><label class="password">Password*</label>&lt;input type="password" name="password" class="input_item03" value="" placeholder=""   tabindex="17" maxlength="16" id="password" size="30" /&gt;&lt;/li>
                <li><label class="confirm_password">Confirm Password*</label>&lt;input type="password" name="passcon" class="input_item03" value="" placeholder="" size="30"  tabindex="18" maxlength="16" /&gt;&lt;/li>
              <div class="membership_form_box_img">
                <h4>Type the words you see below:</h4>
                <br />
                    $publickey = "6LcVYdYSAAAAAFAYBQkfM5HI9GmKfVDd295as0HJ"; // you got this from the signup page
                    echo recaptcha_get_html($publickey);
            <ul class="bottom">

Here's my controller:

public function addToMember(){
            //$this->form_validation->set_rules('mem_type','Membership Type','required|xss_clean');
            $this->form_validation->set_rules('lastname','Last Name','required|xss_clean');
            $this->form_validation->set_rules('firstname','First Name','required|xss_clean');
            $this->form_validation->set_rules('middlename','Middle Name','required|xss_clean');
            $this->form_validation->set_rules('email','Email Address','is_unique[]|valid_email|xss_clean');
            $this->form_validation->set_rules('contact','Mobile Number','required|numeric|is_unique[member.mobile_number]|xss_clean');
if($this->form_validation->run() == FALSE){
                $data['email'] = $this->input->post('email');

And i have a captcha validation like this:
                $privatekey = "6LcVYdYSAAAAAADP4hxndGh2QPuhltCoor9RELjU";
                $resp = recaptcha_check_answer ($privatekey,

                if (!$resp->is_valid){
                    // What happens when the CAPTCHA was entered incorrectly
                    //die ("The reCAPTCHA wasn't entered correctly. Go back and try it again.");
                    return true;

My question is where should i put my captcha validation inside my controller?
Is it the inside my function addToMember()?
How can i display a recaptcha error message in my view?

Or should i create a callback?

Please help me guys...