neondigital / forma

在 Laravel 4/5 以及任何 PHP 项目中玩转表单的好方法。

1.0.0-beta 2024-04-19 09:54 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:34:54 UTC


README

开发中 - 但请随意尝试!

在 Laravel 4 和 PHP 中玩转表单的好方法。不要求使用 Laravel。

需要 PHP 5.4+

对于非 Laravel 使用,调用格式如下。

use Forma\Forma;

$forma = new Forma();
echo $forma->email('email')->id('inputEmail')->required();

巧妙特性

  1. 如果未提供值,则自动从 Input::get() 或 Input::old() 中填充
  2. 自动标签,可以前置或包裹
  3. 复选框即使未选中也会提交(隐藏输入法黑客技巧)
  4. 支持标签和选项文本的语言文件
  5. 在标签内嵌套标签
  6. 自动为标签和字段创建 ID
  7. 方法链,快速完成所需操作并强制其以特定方式表现
  8. 手动添加选择选项,并从数组中添加,非常适合创建“请选择”选项

示例


Forma::populate($user);

Forma::open('user','GET')->class('glenn')->class('bob')->attr('id','sweet');

Forma::open_secure('article')->files();

Forma::text('first_name','glenn<$@£$T£!^;')->class('form-control')->attr('id','first_name');

Forma::text('last_name')->id('inputLast')->forceEmpty();

Forma::email('email')->id('inputEmail')->required();

Forma::password('password')->id('inputPassword')->allowValue();

Forma::input('color')->type('color')->id('inputColor');

Forma::checkbox('confirm',1)->checked();

Forma::open()->child(Forma::checkbox('confirm',1)->omitHidden());

Forma::label()->child(Forma::checkbox('confirm'));

Forma::checkbox('confirm')->withLabel('Please Confirm');

Forma::checkbox('confirm')->id('sweeeetID')->withLabel('Please Confirm');

Forma::input('color')->type('color')->id('inputColor')->withLabel('Pick a color');

Forma::checkbox('confirm')->id('inputConfirm')->wrap('Option One',array('class'=>'checkbox'));

Forma::hidden('secret','thing');

Forma::token();   // Laravel only

Forma::textarea('secret','thi>ng<dd')->rows(10);

Forma::radio('choice')->id('inputChoice')->wrap('Option One',array('class'=>'radio'));

Forma::file('image')->id('inputFile')->wrap('Select Image');

Forma::text('last_name')->id('inputLast')->placeholder('Enter last name');

Forma::text('last_name')->id('inputLast')->placeholder('auth.login_failed');

Forma::label('auth.login_failed');

Forma::label('<i class="fa fa-pound"></i> Price')->rawText();

Forma::select('country')->option('- Please Select -')->option('UK',1,true)->withLabel('Select Country');

Forma::select('country')->options(array('1' => 'United Kingdom', '2' => 'France', '3' => 'USA' ));

Forma::select('town', array('1' => 'Chelmsford', '2' => 'Brentwood', '3' => 'Colchester' ), 2);

Forma::checkbox('cake',1);

Forma::button('Click me!!', 'submit')->class('btn btn-primary');

Forma::submit('submit_btn','Save Changes');

Forma::close();