如何使用ATK4实现图像验证

发布于 2024-12-08 10:07:59 字数 216 浏览 0 评论 0原文

我正在开发一个简单的网络表单来收集网站访问者的反馈。由于访问者未经身份验证,我想为用户实施图像验证步骤。我在 atk4 文档中进行了搜索,但找不到任何类似实现的参考。我还检查了 at4-addons 源代码并找到了两个资源 - View_ReCaptcha 和 Form_Field_Verification。

我不确定我应该遵循哪一个。是否有任何示例代码或教程可供我参考以实现网络表单的图像验证步骤?

I am developing a simple web form to collect feedback from visitors of my website. Since the visitor is not authenticated, I would like to implement an image verification step for the users. I have searched in atk4 documentation and couldn't find any reference for a similar implementation. I have also checked at4-addons source and found two resources - View_ReCaptcha and Form_Field_Verification.

I'm not sure which one should I follow. Is there any example code or tutorial which I can refer to implement a image verification step for my web form?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落墨 2024-12-15 10:07:59

KCapchaAgile Toolkit

这实现了验证码的非常硬核的实现,而不使用任何控制器或视图。当然,不鼓励这样做,但如果您有截止日期,这是您可以使用的最后手段:

$sec_image_field = $f->addField('line', 'sec_image', 'Security code')
    ->setNotNull()
    ->setNoSave();


$captcha_src = '/lib/kcaptcha/?' . $session_name . '=' . session_id();
$kaptcha_img = $sec_image_field->getTag('img',array('src' => $captcha_src, 'id' => 'kpt' ));
$kaptcha_img .= ' <a href="#" onclick="d=new Date(); (jQuery(\'#kpt\')'.
   '.attr(\'src\', \'' . $captcha_src . '&t=\' + d.getTime()));return false;">';
$kaptcha_img .= '<i class="atk-icon atk-icons-nobg atk-icon-arrows-left3"></i>';
$kaptcha_img .= ' reload</a>';
$sec_image_field->template->set('after_field', '<ins>Enther the code you see below</ins> <span>' . $kaptcha_img . '</span>'

注意:您需要从他们的网站下载 kcapcha 并将其安装到 /lib/kcapcha/ 中。

示例:http://agiletech.ie/contact

敏捷工具包 中的 ReCapcha

您发现 ReCapcha 实现要好得多,但并不理想。它手动查看 POST 数据并简单地设置标志来告诉您输入是否正确。以下是用法示例:

$rc = $form->add('View_ReCaptcha');
....
if($form->isSubmitted()){
    ...

    if(!$rc->isValid()){

        $js=$this->js->univ();

        if($r->getError()){
            $js->alert($rc->getError());
        }else{
            $js->alert('Error in capcha');
        }
        $js->execute();
    }
    ....
}

注意:您需要安装 recapcha lib。参见来源。

制作更好的 Capcha

可能最好的方法是引入一种新的字段类型(Form_Field_Capcha),它完全自动完成整个事情。它不应捆绑任何 PHP 库,而应依赖第三方服务来生成图像。它还必须使用标准表单验证

KCapcha in Agile Toolkit

This implements a very hard-core implementation of a captcha, without use of any controllers or views. Of course it's discouraged to code like that, but if you have your deadline, this is the last resort you can use:

$sec_image_field = $f->addField('line', 'sec_image', 'Security code')
    ->setNotNull()
    ->setNoSave();


$captcha_src = '/lib/kcaptcha/?' . $session_name . '=' . session_id();
$kaptcha_img = $sec_image_field->getTag('img',array('src' => $captcha_src, 'id' => 'kpt' ));
$kaptcha_img .= ' <a href="#" onclick="d=new Date(); (jQuery(\'#kpt\')'.
   '.attr(\'src\', \'' . $captcha_src . '&t=\' + d.getTime()));return false;">';
$kaptcha_img .= '<i class="atk-icon atk-icons-nobg atk-icon-arrows-left3"></i>';
$kaptcha_img .= ' reload</a>';
$sec_image_field->template->set('after_field', '<ins>Enther the code you see below</ins> <span>' . $kaptcha_img . '</span>'

Note: you'll need to download and install kcapcha into /lib/kcapcha/ from their website.

Example: http://agiletech.ie/contact

ReCapcha in Agile Toolkit

ReCapcha implementation you have found is much more decent, but not Ideal. It manually looks into the POST data and simply sets flag telling you if it was typed properly or not. Here is example usage:

$rc = $form->add('View_ReCaptcha');
....
if($form->isSubmitted()){
    ...

    if(!$rc->isValid()){

        $js=$this->js->univ();

        if($r->getError()){
            $js->alert($rc->getError());
        }else{
            $js->alert('Error in capcha');
        }
        $js->execute();
    }
    ....
}

Note: You would need recapcha lib installed. See source.

Making better Capcha

Probably the best way would be to introduce a new field type, (Form_Field_Capcha) which does the whole thing completely automatically. It shouldn't bundle any PHP libraries but would rely on 3rd party service for image generation. It also must use the standard form validation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文