承接 assegaiphp/forms 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

assegaiphp/forms

Composer 安装命令:

composer require assegaiphp/forms

包简介

A simple PHP library for dealing with HTML form submissions.

README 文档

README

Assegai Logo

Latest release Tests PHP 8.4+ License Status active

A progressive PHP framework for building effecient and scalable server-side applications.

Description

Assegai is a framework for building efficient, scalable PHP server-side applications. It uses modern PHP (PHP 8.4+) and combines elements of OOP (Object Oriented Programming) and FP (Functional Programming).

Overview

The AssegaiPHP Forms Library is a powerful and flexible tool for managing HTML forms submitted using POST, PUT, or PATCH requests. This library is designed to simplify the process of handling form data, validation, and submission in PHP web applications. It provides a clean and intuitive interface for creating, processing, and validating forms, making it easier for developers to build robust and secure web applications.

Contribution workflow

For commit and pull request conventions in this repo, see:

Git hooks for this repository live in .githooks. Running composer install or composer update will automatically configure core.hooksPath for this clone so the committed pre-push checks are used. If you need to apply the hook configuration manually, run:

composer run hooks:install

Features

  • Form Creation: Easily create HTML forms programmatically using a simple and intuitive syntax.
  • Form Fields: Support for various types of form fields such as text fields, numeric fields, and more.
  • Data Binding: Automatically populate form fields with data from your models or arrays.
  • Validation: Define validation rules for form fields and perform server-side validation effortlessly.
  • Error Handling: Automatically retrieve validation errors for form fields.
  • Customization: Highly customizable rendering and extending capabilities.
  • Compatibility: Works well with modern PHP applications and follows best practices.

Installation

You can install the AssegaiPHP Forms Library using Composer:

composer require assegaiphp/forms

Quick Start

  1. Create a Form:
    use Assegai\Forms\Form;
    use Assegai\Forms\Enumerations\HttpMethod;
    
    $form = new Form(
        method: HttpMethod::POST,
        selector: '#contact-form'
    );
  2. Add Form Fields:
    $form->set('name', '');
    $form->set('email', '');
    $form->set('message', '');
  3. Process Form Submission:
    if ($form->isSubmitted()) {
        // Validate the form
        $form->validate();
        if ($form->isValid()) {
            // Process the form data
            $data = $form->getData();
            // ...
        } else {
            $errors = $form->getErrors();
            // Handle validation errors
        }
    }
  4. Render the Form:
    echo $form->render();

Advanced Usage

Adding Validation Rules

use Assegai\Forms\Form;
use Assegai\Forms\Enumerations\HttpMethod;
use Assegai\Forms\FormControls\TextField;

$form = new Form(method: HttpMethod::POST, selector: '#user-form');

// Create a field with validation rules
$nameField = new TextField('name', '', ['required', 'min:3']);
$form->addField($nameField);

// Or add fields and set validation rules later
$form->set('email', '');
$emailField = $form->getField('email');
$emailField->addValidationRules('required', 'email');

Getting Form Data

// Get data as an associative array
$data = $form->getData();

// Get data as a stdClass object
$dataObject = $form->getData(asObject: true);

Working with Individual Fields

// Check if a field exists
if ($form->has('name')) {
    // Get a specific field value
    $name = $form->getFieldValue('name');

    // Get the field object
    $nameField = $form->getField('name');

    // Remove a field
    $form->removeField('name');
}

Form HTTP Methods

The form supports multiple HTTP methods:

use Assegai\Forms\Enumerations\HttpMethod;

// POST forms
$postForm = new Form(method: HttpMethod::POST, selector: '#form');

// GET forms
$getForm = new Form(method: HttpMethod::GET, selector: '#search');

// PUT/PATCH forms for updates
$updateForm = new Form(method: HttpMethod::PUT, selector: '#update-form');
$patchForm = new Form(method: HttpMethod::PATCH, selector: '#patch-form');

Form Selector

The selector parameter can be used to set the form's ID, CSS class, or action URL:

// Set the form ID
$form = new Form(selector: '#my-form');

// Set the form CSS classes
$form = new Form(selector: '.form-class1.form-class2');

// Set the form action URL
$form = new Form(selector: '/submit-form');

For more detailed usage and customization options, please refer to the Documentation.

Contributing

We welcome contributions from the community! If you'd like to contribute to the AssegaiPHP Forms Library, please follow our Contribution Guidelines.

License

The AssegaiPHP Forms Library is open-source software licensed under the MIT License.

assegaiphp/forms 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-01