laasti / form
v0.2.2
2015-10-28 20:16 UTC
This package is auto-updated.
Last update: 2024-09-20 22:58:32 UTC
README
安装
composer require laasti/form
使用
表单包含包含多个字段的组。
$form = new Laasti\Form\Form($data, $errors, $rules); $form->setMethod('post'); //Defaults to post $form->setAction('url'); $form->setAttributes([/*html attributes*/]); $form->addField('text', 'field', 'Label', [/*choices*/], 'group', [/*input attributes*/], [/*row attributes*/]); $form->removeField('field'); $form->removeGroup('group'); $form->setGroup('field', 'group'); $form->setLabel('field', 'Label'); $form->setType('field', 'type'); $form->setAttributes('field', [/*attributes*/]); $form->setContainerAttributes('field', [/*attributes*/]); $form->setData([]); $form->setErrors([]); $form->setRules([]); $form->setGroupsLayout([ 'top', 'main' => ['column1', 'column2'], 'secondary' => ['side', 'wide'], 'multi-level' => [ 'subsection' => ['sub-column1', 'sub-column2'], 'subsection2' ] ]); $form->defineGroup('group', 'Title', [/*attributes*/]);
然后在你的视图中
$form->getAction(); //Get form action attribute $form->getMethod(); //Get form method $form->getFormAttributes(); //Get form attributes $form->getAllFields(); //All fields without groups $form->getFields(); //Just fields without groups $group = array_shift($form->getGroups()); //Array of first level groups $group->getLabel(); $group->getAttributes(); $group->getGroups(); //Array of subgroups $field = array_shift($group->getFields()); //Array of fields in group $field->getLabel(); $field->getName(); $field->getGroup(); $field->getChoices(); $field->getAttributes(); $field->getContainerAttributes(); //OR you can use magic properties instead of lengthy getters in views $field->choices; $field->containerAttributes; //There are some magic properties as well $field->isRequired;//Checks if required exists in $field->attributes $field->is{Name};//If you want to identify a field by its name $field->is{Type};//If you want to check a field's type
贡献
- 复制它!
- 创建你的功能分支:
git checkout -b my-new-feature
- 提交你的更改:
git commit -am '添加一些功能'
- 推送到分支:
git push origin my-new-feature
- 提交拉取请求 :D
历史
查看 CHANGELOG.md 以获取更多信息。
致谢
作者:Sonia Marquette (@nebulousGirl)
许可
在 MIT 许可证下发布。查看 LICENSE.txt 文件。