定制 preflow/form 二次开发

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

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

preflow/form

Composer 安装命令:

composer require preflow/form

包简介

Preflow form builder — field rendering, model binding, hypermedia integration

README 文档

README

Form builder for Preflow. Renders fields with labels, errors, and help text from a simple template API. Binds to models, reads #[Validate] attributes for type inference and required detection, and auto-enhances forms with inline validation when a hypermedia driver is active.

Installation

composer require preflow/form

Requires preflow/validation and preflow/view. Optionally integrates with preflow/data (model binding) and preflow/htmx (inline validation).

Quick Start

Plain form (no model)

{% set form = form_begin({action: '/contact', csrf_token: csrf_token()}) %}
{{ form.begin()|raw }}
    {{ form.field('name')|raw }}
    {{ form.field('email', {type: 'email'})|raw }}
    {{ form.field('message', {type: 'textarea'})|raw }}
    {{ form.submit('Send')|raw }}
{{ form_end()|raw }}

Model-bound form (inside a component)

{% set form = form_begin({model: game, errorBag: errors}) %}
<form {{ hd.post('save', componentClass, componentId, props)|raw }}>
    {{ form.field('name')|raw }}
    {{ form.select('status', {options: {draft: 'Draft', published: 'Published'}})|raw }}
    {{ form.field('description', {type: 'textarea'})|raw }}
    {{ form.submit('Save')|raw }}
</form>

The form builder reads #[Validate] attributes from the model to infer input types (email rule = type="email"), detect required fields, and populate select options from in: rules.

Field Methods

Method Description
form.field(name, options) Text, email, password, number, date, url, tel, hidden
form.select(name, options) Dropdown with options map
form.checkbox(name, options) Single checkbox
form.radio(name, options) Radio group
form.file(name, options) File upload input
form.hidden(name, value) Hidden input (no label/wrapper)
form.submit(label, options) Submit button

Field Options

Option Description
type Input type (auto-inferred from model rules if bound)
label Label text (auto-generated from field name if omitted)
value Field value (falls back to old input, then model property)
required Required indicator (auto-detected from required rule)
help Help text below the field
errors Error messages (auto-populated from ErrorBag)
attrs Raw HTML attributes passed to the input (escape hatch)
width Width hint for use inside groups ('1/3', '2/3')
options Key-value map for select/radio fields

Field Groups

Group fields for side-by-side layout:

{{ form.group({class: 'form-row', label: 'Address'})|raw }}
    {{ form.field('zip', {width: '1/3'})|raw }}
    {{ form.field('city', {width: '2/3'})|raw }}
{{ form.endGroup()|raw }}

Auto-Generation

Generate fields from model #[Validate] attributes:

{# All validated fields #}
{{ form.fields()|raw }}

{# Cherry-pick #}
{{ form.fields({only: ['name', 'email']})|raw }}

{# Exclude #}
{{ form.fields({except: ['password_hash', 'created_at']})|raw }}

{# Override specific fields #}
{{ form.fields({only: ['name', 'email', 'role'], override: {role: {type: 'select', options: roles}}})|raw }}

Validation Scenarios

Override rules per form for create/update differences:

{% set form = form_begin({
    model: user,
    rules: isEdit
        ? {password: ['nullable', 'min:8']}
        : {password: ['required', 'min:8']}
}) %}

Or use on: directives on the model:

#[Validate('required', 'min:8', 'on:create')]
#[Validate('nullable', 'min:8', 'on:update')]
public string $password = '';
{% set form = form_begin({model: user, scenario: 'create'}) %}

Hypermedia Integration

When inside a component with a hypermedia driver active, the form builder can auto-add inline validation attributes. The attrs escape hatch lets you pass any driver-specific attributes:

{{ form.field('email', {
    attrs: {
        'hx-post': validateUrl,
        'hx-trigger': 'blur delay:300ms',
        'hx-target': 'closest .form-group',
        'hx-swap': 'outerHTML'
    }
})|raw }}

License

MIT

preflow/form 适用场景与选型建议

preflow/form 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 preflow/form 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 preflow/form 我们能提供哪些服务?
定制开发 / 二次开发

基于 preflow/form 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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