Package Data | |
---|---|
Maintainer Username: | robinparisi |
Maintainer Contact: | robin@agence-webup.com (Robin Parisi) |
Package Create Date: | 2015-11-20 |
Package Last Update: | 2024-03-21 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 15:01:56 |
Package Statistics | |
---|---|
Total Downloads: | 6,278 |
Monthly Downloads: | 56 |
Daily Downloads: | 4 |
Total Stars: | 14 |
Total Watchers: | 9 |
Total Forks: | 4 |
Total Open Issues: | 1 |
$ composer require webup/laravel-form
Add this line to config/app.php:
'providers' => [
//...
Webup\LaravelForm\FormServiceProvider::class
]
For shorter code, you can use the facade by adding this line to config/app.php:
'aliases' => [
//...
'Form' => Webup\LaravelForm\Facades\Form::class,
]
You can now use Laravel Form directly into your views (check some examples bellow)
You can publish config and override it in config/form.php:
php artisan vendor:publish
These methods can be used with any type of elements:
{!! Form::create('text', 'name')
->label('Name')
->value('Barney')
->required()
->attr(['maxlenght' => '50'])
->wrapperAttr(['class' => 'f-custom-class']) !!}
Without errors:
<div class="f-group f-custom-class">
<label for="name">Name <i class="f-required">*</i></label>
<input type="text" id="name" name="name" value="Barney" maxlength="50">
</div>
With errors (retrieve from Laravel validation):
<div class="f-group f-custom-class f-error">
<label for="name">Name <i class="f-required">*</i></label>
<input type="text" id="name" name="name" value="Barney" maxlength="50">
<ul class="f-error-message">
<li>Name is required</li>
</ul>
</div>
You can override default CSS class in config/form.php.
Important: Laravel Form can handle HTML generation and client side validation only. You need to manage server side validation on your own.
{!! Form::create('email', 'name')
->label('Email')
->value('homer.simpson@example.com')
->placeholder('example@adresse.com')
->required()
->wrapperAttr(['class' => 'custom-class']) !!}
{!! Form::create('textarea', 'name')
->label('Name')
->value('Nullam id dolor id nibh ultricies vehicula ut id elit.') !!}
{!! Form::create('radio', 'gender')->label('Gender')
->addRadio(1, 'Male', 'male')
->addRadio(0, 'Female', 'female')
->wrapperAttr(['class' => 'custom-class'])
->value(0) !!}
Specific methods :
{!! Form::create('select', 'fruits')
->label("Fruits")
->placeholder("What's your favorite?")
->addOptions(['apple' => 'Apple', 'strawberry' => 'Strawberry', 'melon' => 'Melon'])
->value('apple') !!}
Specific methods :
{!! Form::create('checkbox', 'cgu')
->label("I accept the general terms and conditions")
->value(true) !!}
{!! Form::honeypot("unicorn_mail") !!}
Will create an input text
with name='unicorn_mail'
within a hidden div (by javascript)
$request->validate([
[...]
'unicorn_mail' => 'honeypot',
]);
{!! Form::timetrap("unicorn_time") !!}
Will create an input text
with name='unicorn_time'
and value="{encryptedTimestamp}"
within a hidden div (by javascript)
$request->validate([
[...]
'unicorn_time' => 'timetrap:2',
]);
In this example, timetrap time is set to 2
seconds. If no value is set, config form.antiSpam.minFormSubmitTime
is taken. Finally if config form.antiSpam.minFormSubmitTime
is not set, default value is 3
seconds.
Bellow, you will find default styles that can work with Laravel Form.
.f-group {
margin-bottom: 1rem;
}
.f-group label {
margin-bottom: .5rem;
}
.f-required {
color: #c0392b;
font-weight: bold;
}
.f-error input {
border: 1px solid #c0392b;
}
.f-error-message {
margin-top: 4px;
color: #c0392b;
}
Please see CONTRIBUTING and CONDUCT for details.
Developed by Agence Webup
The MIT License (MIT). Please see License File for more information.