开发者

Can't get reCAPTCHA to work in CodeIgniter

开发者 https://www.devze.com 2023-01-13 14:31 出处:网络
I\'m using the CodeIgniter reCAPTCHA library (here, forum here).For some reason, no variables are being passed from the reCAPTCHA library to the view that has the reCAPTCHA field code.

I'm using the CodeIgniter reCAPTCHA library (here, forum here). For some reason, no variables are being passed from the reCAPTCHA library to the view that has the reCAPTCHA field code.

Here is my controller (the pertinent parts):

$this->load->library('recaptcha');
$this->load->library('form_validation');
$this->lang->load('recaptcha');

// Validate form
...
$this->form_validation->set_rules('recaptcha_response_field','Captcha','required|callback_captcha_check')开发者_如何学JAVA;

And I've tried loading the field view as a variable:

$data['recaptcha'] = $this->load->view('recaptcha',$data,true);

And within my main view:

<?php $this->load->view('recaptcha');?>

Here is the view code:

<script type="text/javascript">
  var RecaptchaOptions = { 
    theme:"<?= $theme ?>",
    lang:"<?= $lang ?>"
  };
</script>
<script type="text/javascript" src="<?= $server ?>/challenge?k=<?= $key.$errorpart ?>"></script>
<noscript> 
        <iframe src="<?= $server ?>/noscript?lang=<?= $lang ?>&k=<?= $key.$errorpart ?>" height="300" width="500" frameborder="0"></iframe><br/>
        <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
        <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>

The library can be found via the links above, but I think it's just a wrapper for the default reCAPTCHA PHP library.

When I access the registration form, the page loads but the reCAPTCHA widget doesn't show up because it throws an error for every variable -- all are undefined.

I'm sure this is something basic about loading variables from a library into a view. Can someone help me out?


Take a look at the view area of the user guide.

http://codeigniter.com/user_guide/general/views.html

It'll show you how to add dynamic data to a view. You usually would do this in your controller.

0

精彩评论

暂无评论...
验证码 换一张
取 消