无法让 reCAPTCHA 在 CodeIgniter 中工作
我正在使用 CodeIgniter reCAPTCHA 库(此处,论坛 此处)。由于某种原因,没有变量从 reCAPTCHA 库传递到具有 reCAPTCHA 字段代码的视图。
这是我的控制器(相关部分):
$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');
我尝试将字段视图加载为变量:
$data['recaptcha'] = $this->load->view('recaptcha',$data,true);
在我的主视图中:
<?php $this->load->view('recaptcha');?>
这是视图代码:
<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>
可以通过上面的链接找到该库,但我认为它只是默认 reCAPTCHA PHP 库的包装器。
当我访问注册表单时,页面会加载,但 reCAPTCHA 小部件不会显示,因为它会为每个变量引发错误 - 所有变量均未定义。
我确信这是将变量从库加载到视图中的基本内容。有人可以帮我吗?
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');
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看用户指南的查看区域。
http://codeigniter.com/user_guide/general/views.html
它将向您展示如何将动态数据添加到视图。您通常会在控制器中执行此操作。
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.