grottopress/form-field

渲染HTML表单字段

v1.0.0 2023-05-31 15:45 UTC

This package is auto-updated.

Last update: 2024-09-23 15:30:59 UTC


README

渲染HTML表单字段。

使用方法

通过composer安装

composer require grottopress/form-field`

实例化和使用如下

<?php
declare (strict_types = 1);

use GrottoPress\Form\Field;

// Text field
$text = new Field([
    'id' => 'field-id',
    'name' => 'field-name',
    'type' => 'text',
    'value' => 'My awesome text field',
    'label' => 'My text field',
]);

// Render text field
echo $text->render();

// Radio buttons
$radio = new Field([
    'id' => 'field-id',
    'name' => 'field-name',
    'type' => 'radio',
    'value' => 'my-choice',
    'choices' => [
        'one' => 'One',
        'my-choice' => 'My Choice',
        'two' => 'Two',
    ],
]);

// Render radio field
echo $radio->render();

// Dropdown
$dropdown = new Field([
    'id' => 'field-id',
    'name' => 'field-name',
    'type' => 'select',
    'value' => 'my-choice',
    'choices' => [
        'one' => 'One',
        'my-choice' => 'My Choice',
        'two' => 'Two',
    ],
]);

// Render dropdown field
echo $dropdown->render();

// Multi-select dropdown
$mdrop = new Field([
    'id' => 'field-id',
    'name' => 'field-name[]',
    'type' => 'radio',
    'value' => 'my-choice',
    'choices' => [
        'one' => 'One',
        'my-choice' => 'My Choice',
        'two' => 'Two',
    ],
    'meta' => [
        'multiple' => 'multiple',
    ],
]);

// Render multi-select dropdown
echo $mdrop->render();

开发

使用composer run test运行测试。

贡献

  1. 进行Fork
  2. 切换到master分支: git checkout master
  3. 创建你的功能分支: git checkout -b my-new-feature
  4. 进行更改,根据需要更新变更日志和文档。
  5. 提交你的更改: git commit
  6. 推送到分支: git push origin my-new-feature
  7. GrottoPress:master分支提交一个新的Pull Request