2017 © Pedro Peláez
 

library form

Make form handling in Laravel simpler.

image

livecontrol/form

Make form handling in Laravel simpler.

  • Tuesday, June 23, 2015
  • by jeffreydevreede
  • Repository
  • 1 Watchers
  • 0 Stars
  • 32 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 28 Forks
  • 0 Open issues
  • 1 Versions
  • 7 % Grown

The README.md

Quick fix for Jeffrey Way's way/form package to make it compatible with LiveControls CMS and Laravel 5.

not compatible with standalone laravel 5

The basic idea is simple: make form creation simpler., (*1)

View a quick visual demonstration., (*2)

I'm tired of creating form fields, like this:, (*3)

<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:, (*4)

{{ FormField::username() }}

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

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

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

This will produce:, (*7)

<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!, (*8)

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

Usage

To try this out:, (*10)

Begin by installing the package through Composer., (*11)

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

Next, add the service provider to app/config/app.php., (*12)

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

That's it! You're all set to go. Try it out in a view:, (*13)

{{ 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., (*14)

output, (*15)

If you want to override the defaults, you can publish the config, like so:, (*16)

php artisan config:publish way/form

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

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

The Versions

23/06 2015

dev-master

9999999-dev

Make form handling in Laravel simpler.

  Sources   Download

The Requires

 

by Jeffrey de Vreede

laravel forms laravel5