定制 gridprinciples/blade-forms 二次开发

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

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

gridprinciples/blade-forms

Composer 安装命令:

composer require gridprinciples/blade-forms

包简介

CSS-agnostic form rendering via Laravel Blade

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A set of Laravel Blade components useful for rendering basic, fully-accessible HTML forms in a Laravel app. The approach is barebones: CSS and JS is not included, but Tailwind (and possibly other framework) presets are planned.

Installation

You can install the package via composer:

composer require gridprinciples/blade-forms

You can publish the config file with:

php artisan vendor:publish --tag="blade-forms-config"

Optionally, you can publish the views using

php artisan vendor:publish --tag="blade-forms"

Usage

<x-form :post="route('form-submission-route')">

    <x-form::input 
        name="name" 
        label="Your name" 
        help="What should we call you?"
        required
        />

    <x-form::radio-buttons 
        name="weekday"
        label="Preferred weekday" 
        :options="[
            'mo' => 'Monday',
            'tu' => 'Tuesday',
            'we' => 'Wednesday',
            'th' => 'Thursday',
            'fr' => 'Friday',
        ]"
        required
        />

    <x-form::checkbox
        name="agree"
        label="I agree with the terms"
        />

</x-form>

Result:

Example of Blade forms rendered output

Text Input

Text inputs are, perhaps, the simplest form element. As with all elements, we can call it using the x-form Blade prefix:

<x-form::input name="username" />

We can continue to decorate this input (and apply some readable indentation):

<x-form::input
    name="username"
    label="Please provide your username"
    help="If you don't have a username yet, use your email."
    required
    />

This gives us an input that's ready to use:

Example input

We can further customize the attributes of the wrapping <div>s and the <label>:

<x-form::input
    name="username"
    label="Please provide your username"
    help="If you don't have a username yet, use your email."
    required
    :wrapperAttributes="[
        'class' => 'form-group-wrapper', 
        'id' => 'username-field',
    ]"
    :labelAttributes="['class' => 'form-label']"
    :inputGroupAttributes="['class' => 'form-input-wrapper']"
    />

Results in:

<div class="form-group-wrapper" id="username-field">
    <label for="username_01" class="form-label">
        Please provide your username*
        <span class="sr-only">(required)</span>
    </label>
    <div class="form-input-wrapper">
        <input id="username_01" name="username" type="text" aria-describedby="username_01_feedback" required="">
    </div>
    <div id="username_01_feedback">
        <div>If you don't have a username yet, use your email.</div>
    </div>
</div>

Textarea

The textarea is used nearly identically to the Input component above:

<x-form::textarea
    name="message"
    label="What would you like to say?"
    rows="2"
    />

Example textarea

Radio buttons

Radio controls should be rendered as a set, with options:

<x-form::radio-buttons
    name="choice"
    label="Do you think so?"
    :options="[
        'yes' => 'Yes',
        'no' => 'No',
        'maybe' => 'Maybe',
    ]"
    value="maybe" {{-- pre-selected option --}}
    />

Example radio buttons

You can customize the option attributes by passing an array instead of a string as the label. Here's how to disable the "Maybe" option:

<x-form::radio-buttons
    name="choice"
    label="Do you think so?"
    :options="[
        'yes' => 'Yes',
        'no' => 'No',
        'maybe' => [
            'label' => 'Maybe',
            'disabled' => true,
        ],
    ]"
    />

Checkbox

A single checkbox can stand alone:

<x-form::checkbox
    name="remember"
    label="Remember me"
    id="remember_checkbox"
    />

Example checkbox

Or, you can render a list of options:

<x-form::checkbox-list
    name="fields"
    label="Which fields can be exported?"
    :options="[
        'name' => 'Full name',
        'email' => 'Email address',
        'phone' => 'Phone number',
        'zip' => 'ZIP code',
    ]"
    />

Example checkbox

Select

Select menu inputs must have options, and can be written in a very similar way to radio and checkbox lists:

<x-form::select
    name="frequency"
    label="How frequently would you like to receive updates?"
    :options="[
        'sync' => 'As soon as anything happens',
        'daily' => 'Daily updates',
        'weekly' => 'Weekly updates',
        'monthly' => 'Monthly updates',
    ]"
    />

Example select input

Form

You can optionally create <form> elements using this component, which includes some shortcuts to make things cleaner. Laravel apps typically have something like this:

<form method="POST" action="{{ route('submission-route') }}">
    @csrf
    @method('PUT')
    {{-- form elements --}}
</form>

Using the <x-form> component, we can simplify things:

<x-form :put="route('submission-route')">
    {{-- form elements --}}
</x-form>

The component will automatically:

  • add the CSRF field
  • add the method based on which variable you fill with your submission URL. You can pass your URL using get, post, put, patch, or delete, and the method will be set for you.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

gridprinciples/blade-forms 适用场景与选型建议

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

它主要适用于以下技术方向: 「laravel」 「blade-forms」 「Grid Principles」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-09