scaleplan / form
另一个表单构建器
Requires
- php: >=7.2
This package is auto-updated.
Last update: 2024-09-16 20:15:34 UTC
README
PHP表单构建器。
安装
composer require scaleplan/form
描述
要生成表单,您需要
- 表单模板
- 形状配置
表单模板是一个HTML文件,其中在其主体中插入了一个新的表单,在最简单的情况下,它可以看起来像这样
<html>
the <head>
<title>example form template</title>
</head>
the <body>
</body>
</html>
配置的大小和复杂程度取决于表单的复杂程度。例如,privedem用户数据编辑表单
labelAfter: 1
invisibleClass: no-display
currentClass: current
currentNumber: 0
templatePath:/views/private/forms/templates
title:
text: Edit user profile
form:
id: main
action:/user/update
novalidate: novalidate
menu:
class: z-depth-3
sections:
- title: Basic
id: main_info
fields:
- fieldWrapper:
class: input-field
type: text
name: login
labelText: Login
data-input: "'mask': 'x{3,}'"
required: required
- fieldWrapper:
class: input-field
type: email
name: email
labelText: E-mail
data-input: "'alias': 'email'"
required: required
- fieldWrapper:
class: input-field
type: tel
name: phone_number
labelText: phone Number
data-input: "'mask': '+7 (999) 999-99-99'"
buttons:
- text: Forward
class: next
- title: Career
id: carrier
fields:
- fieldWrapper:
class: input-field
type: select
name: education
labelText: Education
- fieldWrapper:
class: input-field
type: text
name: job_place
labelText: place of work
- fieldWrapper:
class: input-field
type: text
name: post
labelText: Position
buttons:
- text: Back
class: prev
- text: Forward
class: next
- title: Avatar
id: avatar
fields:
- type: file
template: thumb_template.html
name: image
labelText: Upload your avatar
class: 'image thumb'
buttons:
- text: Back
class: prev
buttons:
- class: reset
- type: submit
考虑配置指令
- labelAfter - 在字段后生成标签;
invisibleClass - 用于元素隐藏的类;
-
currentClass - 表示选中菜单项的类(表示表单的选中部分);
-
currentNumber - 默认选择的表单部分;
-
templatePath - 表单模板的绝对路径;
-
title - 表单标题的描述,text - 标题文本,您还可以添加任何HTML属性,如id、class等...
-
form - 表单本身的属性(《form》标签);
-
menu - 表单菜单属性(《menu》标签),如果表单有部分(`sections`),则有意义;
-
sections - 带属性的表单部分。此外,菜单是通过部分形成的:菜单项(《a》标签)具有与部分《title》属性相同的锚点,如果部分有《id》,例如《main_info》,则相应的菜单项将具有《href="#main_info"`。如果表单不需要划分部分,则可以省略这部分,然后《fields`将在根配置中;
-
fields - 表单字段,属性,模板及其包装器,如果需要
- 模板在需要使用HTML模板而不是空白表单字段时使用,例如,输入,并已设置属性的自定义元素;
- 包装器是将表单元素包装进其中的元素,默认为《div`,即从
- fieldWrapper: class: input-field
生成的包装器将是
<div class= "input-field" ></div>
-
buttons - 在部分上下文中,这些是带有属性的该部分的按钮,在表单上下文中 - 对于所有部分通用的按钮。
很简单。尽管表单的配置可能很大,但将其降级到HTML模型是非常容易的
现在开始生成
$form = new Form(Yaml:: parse(file_get_contents('user.yml')));
echo $form->render();
就这些。输出将是表单。