Welcome Guest, Not a member yet? Register   Sign In
recaptcha validation message
#1

[eluser]vile[/eluser]
i followed the steps in recaptcha codeigniter wiki.

it seems that validation->set_message doesnt work. here's the validation message "Unable to access an error message corresponding to your field name."

here's my code:

controller:
Code:
function signup(){
         $data = array();
        print_r($_POST);        
        $data = array('captcha' => $this->recaptcha->recaptcha_get_html());
        $data['message'] = "";    
        

        //form validation
        $this->form_validation->set_rules('firstname', 'firstname', 'required|required|min_length[3]|alpha|trim');
        $this->form_validation->set_rules('lastname', 'lastname', 'required|min_length[3]|alpha|trim');
        $this->form_validation->set_rules('email', 'email', 'required|valid_email|trim');
        $this->form_validation->set_rules('gender', 'gender', 'required');        
        $this->form_validation->set_rules('day', 'day', 'required');
        $this->form_validation->set_rules('month', 'month', 'required');
        $this->form_validation->set_rules('year', 'year', 'required');
        $this->form_validation->set_rules('password', 'password', 'required|matches[passwordconf]|min_length[6]|trim|md5');
        $this->form_validation->set_rules('passwordconf', 'password confirmation', 'required');
        $this->form_validation->set_rules('recaptcha_response_field', 'captcha', 'required|callback_check_captcha');

                
                

        
        if ($this->form_validation->run() == FALSE)
        {
            //set custom message    
            $this->form_validation->set_message('firstname', 'You must enter your first name.');
            $this->form_validation->set_message('lastname', 'You must enter your last name.');
            $this->form_validation->set_message('gender', 'You must select your gender.');
            $this->form_validation->set_message('email', 'Sorry. Invalid email address. Please use your real email address..');
            $this->load->view('signupForm',$data);
        }
        else
        {
            
                $data = $this->mainmodel->process_signup();
            

            if($data['queryresult']){
                $this->load->view('signupsuccess',$data);
            }else{
                $this->load->view('signupForm',$data);
            }
        }
    
     }
    
     function check_captcha($val) {
          $this->recaptcha->recaptcha_check_answer($_SERVER["REMOTE_ADDR"],$this->input->post('recaptcha_challenge_field'),$val);
          if ($this->recaptcha->is_valid) {
            return true;
          } else {
            $this->form_validation->set_message('recaptcha_response_field','Incorrect Security Image Response');
            return false;
          }
      }

btw my custom message wont work too. can you please tell what i did wrong? i been stuck here fo a while. thanks for your help Big Grin
#2

[eluser]TheFuzzy0ne[/eluser]
Beats me... Can you confirm that it's definitely the "recaptcha_response_field" field that's causing the problem? Might also be worth setting your logging to verbose and checking the log file to see if there's anything of interest in there.
#3

[eluser]vile[/eluser]
thanks for your response.
yes its the captcha_response_field. if i dont put anything in the captcha field, the validation works. but if i enter wrong validation code the error comes out. im really confused in error messages. it just wont work and i dont know why??? is there something wrong in my code?? please help me thanks.
#4

[eluser]TheFuzzy0ne[/eluser]
I can't see anything wrong with the code. The only things i can suggest are a) clear your browser's cache, and b) try moving the $this->form_validation->set_message() line in the validation function, up to where the others are. I doubt it will help, but I'm at a loss for answers.

Sorry.
#5

[eluser]vile[/eluser]
thanks i tried but it didnt work Sad anyone?
anyway this is the captcha's form.

Code:
[removed]
  var RecaptchaOptions = {
    theme:"<?= $theme ?>"
  };
[removed]
[removed][removed]

<noscript>
        &lt;iframe src="&lt;?= $server ?&gt;/noscript?k=&lt;?= $key.$errorpart ?&gt;" height="300" width="500" frameborder="0"&gt;&lt;/iframe><br/>
        &lt;textarea name="recaptcha_challenge_field" rows="3" cols="40"&gt;&lt;/textarea>
        &lt;input type="hidden" name="recaptcha_response_field" value="manual_challenge"/&gt;
</noscript>




Theme © iAndrew 2016 - Forum software by © MyBB