miraafaq/askme
Composer 安装命令:
composer require miraafaq/askme
包简介
Basic Form Generator
README 文档
README
ArtifyForm is a modern, lightweight, incredibly flexible PHP form builder designed to eliminate markup and tedious boilerplate attribute handling. Easily generate HTML forms, perform server-side validation, manage grid layouts, re-populate old inputs, and integrate natively into frameworks.
Table of Contents
- Installation
- Quickstart Usage Example
- Field Types & Methods
- Validation Engine
- Layouts & Fieldsets
- Framework Integrations
- Custom Extensions
Installation
via composer:
composer require miraafaq/artifyform
Quickstart Usage Example
Build beautiful, self-validating forms in minutes using fluid APIs without ever touching <form> HTML manually!
<?php require_once __DIR__ . '/vendor/autoload.php'; use ArtifyForm\ArtifyForm; use ArtifyForm\Fieldset; use ArtifyForm\Field\TextField; use ArtifyForm\Field\EmailField; use ArtifyForm\Field\ButtonField; // 1. Initialize Builder $formBuilder = new ArtifyForm('submit.php', 'POST'); $formBuilder->setFormId('registration-form'); // 2. Add Native HTML (Headers) $formBuilder->addHtml('<h2>Register Account</h2>'); // 3. Create Fluent Fields $firstName = (new TextField('first_name')) ->label('First Name') ->placeholder('e.g. John') ->rules(['required', 'min:3']); $email = (new EmailField('email')) ->label('Email Address') ->rules(['required', 'email']); $submitBtn = (new ButtonField('register_btn'))->type('submit')->value('Create Account')->class('artifyform-btn-primary'); // 4. Arrange in layout grid $formBuilder->addRow([$firstName, $email]); $formBuilder->addField($submitBtn); // 5. Automatic Validation if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($formBuilder->validate($_POST)) { // Safe arrays! $cleanData = $formBuilder->getValidatedData(); } else { // Errors natively inject into their form fields $errors = $formBuilder->getErrors(); } } // 6. Generate (Outputs inline styled base CSS and completed HTML tags) echo $formBuilder->generateCss(); echo $formBuilder->generateForm();
Field Types & Methods
All fields inherit from AbstractField allowing you to completely chain settings directly upon initialization.
Base Chainable Methods
->label('My Field') // Renders visual label ->placeholder('Hint text') // Sets input placeholder ->helperText('Extra desc') // Adds small instruction text under field ->value('Default Value') // Sets default input ->class('custom-class') // Appends an extra CSS class ->attr('data-id', 123) // Pushes any custom attribute ->required() // Adds native HTML5 required="" parameter ->rules(['required', '...']) // Initiates PHP Server-Side validation rules
Available Field Types
TextField: Standard<input type="text">EmailField:<input type="email">PasswordField:<input type="password">HiddenField: Invisible field for storing metadata or User IDs.NumberField: Supports incrementing numbers (supports->attr('min', 1))DateField: Native HTML5 Calendar UI.ColorField: Native Hex Color Picker UI.TextAreaField: Long paragraph box.FileField: Seamlessly converts<form>toenctype="multipart/form-data"!CheckboxField: Supports a clean single toggle option.RadioField: Define array options via->options(['m'=>'Male', 'f'=>'Female']).SelectField: Standard<select>dropdown (uses->options([])).MultiSelectField: Multiple selection<select multiple>. Intelligently adds[]suffix to field name to auto-hydrate values as PHP Array!WysiwygField: Standalone Rich-Text-Editor (Requires Zero Dependencies!). Contains localized Javascript for Bold, Italics, and Underlines piping to a hidden<textarea>.ButtonField: Triggers submission<button type="submit">.
Validation Engine
Add validation rule strings using ->rules(['rule:value']) on any field.
Available Rules:
'required': Input must not be empty.'email': Standard PHPFILTER_VALIDATE_EMAIL.'numeric': Must be number format.'min:{x}': Minimum string length (e.g.min:8for passwords).'max:{x}': Maximum string length (e.g.max:255).
If $formBuilder->validate($_POST) fails, ArtifyForm remembers the user's previously typed inputs and automatically paints the error text in red beneath the targeted field dynamically.
Layouts & Fieldsets
By default, inputs stack downwards. To implement styling you can use Grids or HTML Fieldset Groups.
Grids (Rows):
Display elements side-by-side using addRow().
$formBuilder->addRow([ (new TextField('first_name'))->label('First Name'), (new TextField('last_name'))->label('Last Name') ]);
Fieldset Containers: Bundle related fields under a visually pleasing boundary.
$billingFields = new \ArtifyForm\Fieldset('Billing Address'); $billingFields->addRow([$country, $zipcode]); $formBuilder->addField($billingFields);
Framework Integrations
ArtifyForm natively supports specific platform bindings!
1. Laravel Native
Because ArtifyForm ships via composer using extra.laravel.providers, its Core Service Provider is automatically discovered! Immediately use standard blade directives targeting an inherited $formBuilder variable passed through your Controller:
<!-- Places base CSS block in Head --> @artifyform_css($formBuilder) <!-- Outputs your configured form anywhere --> @artifyform_form($formBuilder)
2. WordPress Appending
Register forms to shortcodes natively using ArtifyFormWP! Place this inside functions.php:
use ArtifyForm\Integration\WordPress\ArtifyFormWP; ArtifyFormWP::registerShortcode('contact_us_form', function($atts) { $form = new \ArtifyForm\ArtifyForm(); // Configure $form ... return $form; });
Then output [contact_us_form] inside any Post layout!
3. Razorpay Implementation
Instantly mount a popup Razorpay Button simply by adding it exactly like an input field!
use ArtifyForm\Integration\Razorpay\RazorpayButton; $payBtn = clone (new RazorpayButton('rzp_test_KEY123', 50000, 'My Company')) ->theme('#ff5500') ->prefill('John Doe', 'email@test.com', '9999999999'); $formBuilder->addField($payBtn);
Custom Extensions
ArtifyForm architecture rests strictly upon SOLID formatting.
You can override or invent new components infinitely without touching source code by simply implementing RenderableInterface.
<?php class CustomInput implements \ArtifyForm\Contract\RenderableInterface { public function render(): string { return "<div class='mystyle'>My brand new HTML feature</div>"; } } // Inject directly! $formBuilder->addField(new CustomInput());
Testing Framework
To run validations in dev structures use PHPUnit:
composer require phpunit/phpunit --dev vendor/bin/phpunit
Author
miraafaq/askme 适用场景与选型建议
miraafaq/askme 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 7, 最近一次更新时间为 2023 年 08 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 miraafaq/askme 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 miraafaq/askme 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-only
- 更新时间: 2023-08-31