Welcome Guest, Not a member yet? Register   Sign In
how to validate a recaptcha plugin using a controller?
#1

[eluser]rochellecanale[/eluser]
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:

Code:
<?php $attr = array('name'=>'member', 'id' => 'formID'); ?>
<?php echo form_open('payment_controller/addToMember',$attr); ?>
.
.
.
.
  <div class="membership_form_box">
              <ul>
                <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>
              </ul>
              <div class="membership_form_box_img">
                <h4>Type the words you see below:</h4>
                <br />
                &lt;?php
                
                    require_once('recaptcha/recaptchalib.php');
                    $publickey = "6LcVYdYSAAAAAFAYBQkfM5HI9GmKfVDd295as0HJ"; // you got this from the signup page
                    echo recaptcha_get_html($publickey);
                
               ?&gt;
              </div>
            </div>
            <ul class="bottom">
.
.
.

Here's my controller:

Code:
public function addToMember(){
    
            $this->form_validation->set_rules('username','Username','required|trim|min_length[8]|max_length[15]|is_unique[free_member.username]|xss_clean');
            //$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[member.email]|valid_email|xss_clean');
            $this->form_validation->set_rules('contact','Mobile Number','required|numeric|is_unique[member.mobile_number]|xss_clean');
            $this->form_validation->set_rules('gender','Gender','required|xss_clean');
.
.
.
if($this->form_validation->run() == FALSE){
            
                $this->load->view('sites/addNewMember');
                
            }else{
                $data['email'] = $this->input->post('email');
                $this->payment_model->addMemberInfo();
                $this->load->view('sites/success',$data);
            }

And i have a captcha validation like this:
Code:
if(isset($this->input->post['cmdweblogin'])){
                
                require_once('recaptcha/recaptchalib.php');
                $privatekey = "6LcVYdYSAAAAAADP4hxndGh2QPuhltCoor9RELjU";
                $resp = recaptcha_check_answer ($privatekey,
                    $_SERVER["REMOTE_ADDR"],
                    $_POST["recaptcha_challenge_field"],
                    $_POST["recaptcha_response_field"]);

                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.");
                    location.href('http://www.google.com/recaptcha/api/verify');
                  
                }else{
                    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...





Theme © iAndrew 2016 - Forum software by © MyBB