此包最新版本(dev-master)没有可用的许可证信息。

使Laravel中的表单处理更简单。

dev-master 2015-06-23 18:15 UTC

This package is not auto-updated.

Last update: 2024-09-18 08:53:44 UTC


README

与独立Laravel 5不兼容

基本思路很简单:使表单创建更简单。

查看快速视觉演示。

我厌倦了创建这样的表单字段

<div class="form-group">
    {{  Form::label('username', 'Username:' ) }}
    {{ Form::text('username', null, ['class' => 'control-group']) }}
</div>

相反,使用这个 FormField 类,你可以简单地做

{{ FormField::username() }}

这将生成必要的(默认为Bootstrap友好的)HTML。它使用动态方法来简化过程。

虽然它将尽力确定你想要的输入类型,但你也可以覆盖它。

{{ FormField::yourBio(['type' => 'textarea']) }}

这将生成

<div class='form-group'>
    <label for="yourBio">Your Bio: </label>
    <textarea class="form-control" type="textarea" name="yourBio" cols="50" rows="10" id="yourBio"></textarea>
</div>

所以,是的,它只是一个辅助类。如果你的表单需要大量的定制,这可能不适合你。但对于简单的表单,它会很有效地完成任务!

(它还使得Laracasts演示的设置变得非常容易。 :)

用法

要尝试这个

首先通过Composer安装包。

require: {
    "livecontrol/form": "dev-master"
}

然后,将服务提供者添加到 app/config/app.php

'providers' => [
    // ..
    'Way\Form\FormServiceProvider'
]

这就完成了!你现在可以开始使用了。在视图中试试看

{{ FormField::username() }}
{{ FormField::email() }}
{{ FormField::custom(['type' => 'textarea']) }}
{{ FormField::address(['label' => 'Your Address']) }}

这将生成以下内容。虽然默认情况下它是Twitter Bootstrap友好的,但你可以根据自己的意愿自定义类名。

output

如果你想覆盖默认设置,可以像这样发布配置

php artisan config:publish way/form

现在,访问 app/config/packages/way/form/config.php 进行自定义。以下是默认列表

return [

    /*
     * What should each form element be
     * wrapped within?
    */
    'wrapper' => 'div',

    /*
     * What class should the wrapper
     * element receive?
    */
    'wrapperClass' => 'form-group',

    /**
     * Should form inputs receive a class name?
     */
    'inputClass' => 'form-control',

    /**
     * Frequent input names can map
     * to their respective input types.
     *
     * This way, you may do FormField::description()
     * and it'll know to automatically set it as a textarea.
     * Otherwise, do FormField::thing(['type' => 'textarea'])
     *
     */
    'commonInputsLookup'  => [
        'email' => 'email',
        'emailAddress' => 'email',

        'description' => 'textarea',
        'bio' => 'textarea',
        'body' => 'textarea',

        'password' => 'password',
        'password_confirmation' => 'password'
    ]
];