定制 mzur/kirby-form 二次开发

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

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

mzur/kirby-form

最新稳定版本:v3.3.0

Composer 安装命令:

composer require mzur/kirby-form

包简介

A form helper for Kirby-based websites, using the Post/Redirect/Get pattern.

关键字:

README 文档

README

Tests

This is a fork of jevets\kirby-form.

A helper library for working with Kirby forms, using the Post/Redirect/Get design pattern.

Quick Example

$form = new Form([ 'name' => [ 'rules' => ['required'], 'message' => ['Name is required'] ], 'phone' => [], ]); if ($form->validates()) { // Validation passed // Do something with the data }

Installation

Install with composer:

# Kirby 2 composer require mzur/kirby-form:^1.0 # Kirby 3 composer require mzur/kirby-form:^2.0

Basic Example

This example assumes you're using page controllers in Kirby and that your page's URI is /my-page.

// site/templates/my-page.php <?php snippet('header') ?> <?php snippet('form-errors', ['form' => $form]) ?> <form method="POST"> <input name="name" value="<?= $form->old('name') ?>"> <input name="phone" value="<?= $form->old('phone') ?>"> <?= csrf_field() ?> <input type="submit" value="Submit"> </form> <?php snippet('footer') ?>
// site/snippets/form-errors.php <?php if (count($form->errors()) > 0): ?> <div class="alert alert-error"> <?php foreach ($form->errors() as $key => $errors): ?> <div><?= implode('<br>', $errors) ?></div> <?php endforeach ?> </div> <?php endif ?>
// site/controllers/my-page.php use Jevets\Kirby\Form; return function ($kirby) { // Initialize the Form $form = new Form([ 'name' => [ 'rules' => ['required'], 'message' => ['Name is required'] ], 'phone' => [], ]); // Process the form on POST requests if ($kirby->request()->is('POST')) { if ($form->validates()) { // Show a thanks page } else { // Redirect back to the GET form go('/my-page'); } } return compact('form'); };

Contributing

Feel free to send a pull request!

Issues/Bugs

Please use the GitHub issue tracker.

统计信息

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

GitHub 信息

  • Stars: 8
  • Watchers: 2
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04