2017 © Pedro Peláez
 

library semantic-form

Semantic-UI form helpers

image

laravolt/semantic-form

Semantic-UI form helpers

  • Thursday, October 19, 2017
  • by uyab
  • Repository
  • 7 Watchers
  • 47 Stars
  • 4,532 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 10 Forks
  • 3 Open issues
  • 33 Versions
  • 4 % Grown

The README.md

Semantic Form

SensioLabsInsight Travis Coverage Status, (*1)

Semantic UI form builder, for Laravel., (*2)

Installation

``` bash $ composer require laravolt/semantic-form, (*3)


## API **Note: You can use either facade `Form::method()` or helper `form()->method()`.** ### Opening Form ``` php Form::open('search'); // action="search" Form::open()->get(); Form::open()->post(); Form::open()->put(); Form::open()->patch(); Form::open()->delete(); Form::open(); // default to method="GET" Form::open()->action('search'); Form::open()->url('search'); // alias for action() Form::open()->route('route.name'); Form::open()->post()->action(route('comment.store'));

Opening Form (Short Syntax, Since 1.10)

``` php Form::open('search'); // action="search" method=POST Form::get('search'); // action="search" method=GET Form::post('search'); // action="search" method=POST Form::put('search'); // action="search" method=POST _method=PUT Form::patch('search'); // action="search" method=POST _method=PATCH Form::delete('search'); // action="search" method=POST _method=DELETE, (*4)


### CSRF Token CSRF token will automatically generated if current form method is `POST`. To prevent token generation, you can call `withoutToken()` when opening a form. ``` php Form::post('search')->withoutToken();

Text

``` php Form::text($name, $value)->label('Username');, (*5)


### Number ``` php Form::number($name, $integerValue)->label('Total');

Rupiah

``` php Form::rupiah($name, $defaultValue = null)->label('Price');, (*6)


### Date ``` php Form::date($name, $value)->label('Birthday');

Time

``` php Form::time($name, $value)->label('Start Time');, (*7)


### Password ``` php Form::password($name)->label('Password');

Email

``` php Form::email($name, $value)->label('Email Address');, (*8)

### Textarea
``` php
Form::textarea($name, $value)->label('Note');

Select Box (Dropdown)

``` php Form::select($name, $options)->label('Choose Country'); Form::select($name, $options, $selected)->label('Choose Country'); Form::select($name, $options)->placeholder('--Select--'); Form::select($name, $options)->appendOption($key, $label); Form::select($name, $options)->prependOption($key, $label);, (*9)


### Select Date & Select Date Time ``` php Form::selectDate('myDate', $startYear, $endYear)->label('Birth Date'); Form::selectDateTime('myDate', $startYear, $endYear, $intervalInMinute)->label('Schedule');

By default, selectDate and selectDateTime will post request as _myDate with ['date'=>4, 'month'=>5, 'year'=>2016] for example. To get 2016-5-4 format, you need to register middleware and use it in the routes., (*10)

protected $routeMiddleware = [
    'selectdate' => \Laravolt\SemanticForm\Middleware\SelectDateMiddleware::class,
    'selectdatetime' => \Laravolt\SemanticForm\Middleware\SelectDateTimeMiddleware::class
];
Route::post('myForm', ['middleware' => ['web', 'selectdate:myDate'], function (\Illuminate\Http\Request $request) {
    dd($request->input('myDate')); // Will output 2016-5-4
}]);

Select Range

``` php Form::selectRange($name, $begin, $end)->label('Number of child');, (*11)


### Select Month ``` php Form::selectMonth($name, $format = '%B')->label('Month');

Radio

``` php $checked = true; Form::radio($name, $value, $checked)->label('Item Label');, (*12)


### Radio Group ``` php $values = ['apple' => 'Apple', 'banana' => 'Banana']; $checkedValue = 'banana'; Form::radioGroup($name, $values, $checkedValue)->label('Select Fruit');

Checkbox

``` php Form::checkbox($name, $value, $checked)->label('Remember Me');, (*13)


### Checkbox Group ``` php $values = ['apple' => 'Apple', 'banana' => 'Banana']; $checkedValue = 'banana'; Form::checkboxGroup($name, $values, $checkedValue)->label('Select Fruit');

File

``` php Form::file($name);, (*14)

### Input Wrapper
``` php
Form::input($name, $defaultvalue);
Form::input($name, $defaultvalue)->appendIcon('search');
Form::input($name, $defaultvalue)->prependIcon('users');
Form::input($name, $defaultvalue)->appendLabel($label);
Form::input($name, $defaultvalue)->prependLabel($label);
Form::input($name, $defaultvalue)->type("password");

Reference: http://semantic-ui.com/elements/input.html, (*15)

Datepicker

``` php Form::datepicker($name, $value, $format);, (*16)

// Valid $format are: // DD -> two digit date // MM -> two digit month number // MMMM -> month name (localized) // YY -> two digit year // YYYY -> full year, (*17)

// To convert localized format to standard (SQL) datetime format, you can use Jenssegers\Date\Date library (already included): // Jenssegers\Date\Date::createFromFormat('d F Y', '12 februari 2000')->startOfDay()->toDateTimeString(); // Jenssegers\Date\Date::createFromFormat('d F Y', '12 februari 2000')->startOfDay()->toDateString();, (*18)


### Timepicker ``` php Form::timepicker($name, $value);

Hidden

``` php Form::hidden($name, $value);, (*19)


### Button ``` php Form::button($value);

Submit

``` php Form::submit($value);, (*20)


### Model Binding #### Version 1 ``` php {!! Form::bind($model) !!}

Version 2

``` php // as parameter for method open() {!! Form::open($route, $model) !!}, (*21)

// or chaining it {!! Form::bind($model)->get($route) !!}, (*22)


#### Warning ```php // This is OK in version 1, but will produce error in version 2 {!! Form::bind($model) !!}

Macro

Macro definition, put it anywhere within your application, e.g. AppServiceProvider:, (*23)

Form::macro('trix', function ($id, $name, $value = null) {
    return sprintf(
        "%s %s", 
        Form::hidden($name, $defaultValue)->id($id), 
        "<trix-editor input='{$id}'></trix-editor>"
    );
});

And then call it like any other method:, (*24)

Form::trix('contentId', 'content', '<b>some content</b>');

Action

``` php // Method 1, (*25)

Form::action(Form::submit('Save'), Form::button('cancel'));, (*26)

// Method 2, (*27)

// Assumed you already define some macros: Form::macro('submit', function(){ return form()->submit('Submit'); });, (*28)

Form::macro('cancel', function(){ return form()->button('Cancel'); });, (*29)

// Then you can just call macro name as string Form::action('submit', 'cancel');, (*30)

// Method 3, (*31)

// Even further, you can define macro thats just wrap several buttons: SemanticForm::macro('default', function(){ return new \Laravolt\SemanticForm\Elements\Wrapper(form()->submit('Submit'), form()->submit('Submit')); });, (*32)

// And then make the call simplier: Form::action('default');, (*33)


### General Function For every form element, you can call and chaining following methods: * id($string) * addClass($string) * removeClass($string) * attribute($name, $value) * data($name, $value) * hint($text) (Since 1.10.0) * hint($text, $class = "hint") (Since 1.10.2) #### Override Hint class globally (Since 1.10.2) ``` php // Put this on every request, e.g. in AppServiceProvider Laravolt\SemanticForm\Elements\Hint::$defaultClass = 'custom-class';

Example

php Form::text($name, $value)->label('Username')->id('username')->addClass('foo'); Form::text($name, $value)->label('Username')->data('url', 'http://id-laravel.com'); Form::password($name, $value)->label('Password')->hint('Minimum 6 characters'); Form::password($name, $value)->label('Password')->hint('Minimum 6 characters', 'my-custom-css-class');, (*34)

Middleware

  • \Laravolt\SemanticForm\Middleware\SelectDateMiddleware
  • \Laravolt\SemanticForm\Middleware\SelectDateTimeMiddleware

Credits

SemanticForm inspired by AdamWathan\Form., (*35)

The Versions

19/10 2017

dev-master

9999999-dev https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

04/09 2017

1.10.8

1.10.8.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

07/08 2017

1.10.7

1.10.7.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

16/06 2017

1.10.6

1.10.6.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

09/06 2017

1.10.5

1.10.5.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

04/06 2017

1.10.4

1.10.4.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

02/06 2017

1.10.3

1.10.3.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

31/05 2017

1.10.2

1.10.2.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

31/05 2017

1.10.1

1.10.1.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

25/05 2017

1.10

1.10.0.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

12/05 2017

1.9.4

1.9.4.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

11/05 2017

1.9.3

1.9.3.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

10/05 2017

1.9.2

1.9.2.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

22/03 2017

1.9.1

1.9.1.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

21/02 2017

1.9.0

1.9.0.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

03/02 2017

1.8.0

1.8.0.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

04/10 2016

1.7.0

1.7.0.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

01/09 2016

1.6.0

1.6.0.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

31/08 2016

dev-datepicker

dev-datepicker https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

15/08 2016

1.5.1

1.5.1.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

15/08 2016

1.5.0

1.5.0.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

11/08 2016

1.4.0

1.4.0.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

04/04 2016

1.3.0

1.3.0.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

04/04 2016

2.0.x-dev

2.0.9999999.9999999-dev https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

21/01 2016

1.1.1

1.1.1.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

19/01 2016

1.1.0

1.1.0.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

14/01 2016
08/01 2016

1.0.2

1.0.2.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

06/01 2016

1.0.1

1.0.1.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

06/01 2016

1.0.0

1.0.0.0 https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

06/01 2016

0.x-dev

0.9999999.9999999.9999999-dev https://github.com/laravolt/semantic-form

Semantic-UI form helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel form semantic-ui laravolt

09/11 2015