首页 > 解决方案 > 使用 Symfony 3 在 HTML 中添加验证码

问题描述

嗨,我想在 Symfony 3.4 项目中以 html 形式使用验证码,我成功安装并实现了验证码包(Gregwar 的 CaptchaBundle),但在包的文档中,将验证码添加到他们正在使用 symfony 表单生成器的表单中但我正在使用 requests 处理普通的 HTML 表单。这是他们在捆绑包文档中提供的代码:

<?php
    use Gregwar\CaptchaBundle\Type\CaptchaType;
    // ...
    $builder->add('captcha', CaptchaType::class); // That's all !
    // If you're using php<5.5, you can use instead:
    $builder->add('captcha', 'Gregwar\CaptchaBundle\Type\CaptchaType');
    // ...

这是我要在其中添加验证码的 html 表单

    <form class="row" method="post"   action="{{path('envoyerchat')}}">
        <input type="text" name="test2">
        <input type="text" name="test1">
        <!-- add captcha here -->
        <!-- add captcha here -->
        <input type="submit">
    </form>

我可以将与 fom builder 一起使用的代码转换为我的 html 表单吗?

标签: formssymfonybundlecaptcha

解决方案


推荐阅读