Giter VIP home page Giter VIP logo

laravel-formfield's Introduction

The basic idea is simple: make form creation simpler.

View a quick visual demonstration.

I'm tired of creating form fields, like this:

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

Instead, with this FormField class, you can simply do:

{{ FormField::username() }}

That will then produce the necessary (Bootstrap-friendly, by default) HTML. It uses dynamic methods to simplify the process a bit.

While it will do its best to figure out what kind of input you want, you can override it.

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

This will produce:

<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>

So, yeah, it's just a helper class. If your forms require a huge amount of customization, this probably won't work for you. But for simple forms, it'll do the trick nicely!

(It also makes Laracasts demos way easier to setup. :)

Usage

To try this out:

Begin by installing the package through Composer.

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

Next, add the service provider to app/config/app.php.

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

That's it! You're all set to go. Try it out in a view:

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

That will produce the following. Though it's Twitter Bootstrap friendly by default, you can of course customize the class names as you wish.

output

If you want to override the defaults, you can publish the config, like so:

php artisan config:publish way/form

Now, access app/config/packages/way/form/config.php to customize. Here's what it lists by default:

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'
    ]
];

laravel-formfield's People

Watchers

James Cloos avatar edyonil avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.