定制 click66/psr-forms 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

click66/psr-forms

最新稳定版本:0.2.0

Composer 安装命令:

composer require click66/psr-forms

包简介

PSR-compliant form handling and rendering for PHP

README 文档

README

Very simple stateless form renderer and handler, compliant with PSR request and response interfaces.

Still a work in progress.

Currently utilises the Formr library (https://github.com/formr/formr) as a base.

Example usage

Simple implementation

$factory = new \Click66\Forms\Factory();
$formr = \Click66\Forms\Formr\Adaptr();

$formRenderer = $factory->makeFormRenderer($formr);
$formHandler = $factory->makeFormHandler($formr);

# In your POST route:
$response = $formHandler->process(
    $request,   # PSR-7 RequestInterface
    ['Name(required)', 'Message(required)'],
    function ($data) {
        var_dump($data);    # $data contains the validated form data
        
        if (true) { # Do something with your data
            return new \Click66\Forms\Result\Success('Thank you for using the service!');   # Messages flashed to session
        } else {
            return new \Click66\Forms\Result\Failure('Something has gone wrong, please try again later.');
        }
    }
)->respond(fn () => response(303)->withHeader('Location', '/form'));    # Return a PSR response. Will run at conclusion of form processing, regardless of outcome.

Captcha usage

$captcha = new \Click66\Forms\Captcha\Captcha(
    new \Click66\Forms\Captcha\Credentials(...),
    new \Click66\Forms\Captcha\RecaptchaV2\Verifier(...),   # Currently supports Google ReCaptcha v2.
)
$factory = (new \Click66\Forms\Factory())->withCaptcha($captcha);

# The rest is the same - CAPTCHA will be processed and validated automatically

统计信息

  • 总下载量: 38
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-only
  • 更新时间: 2023-10-17