{"_id":"563c2233d8f2d20d00448b4f","user":"563b65409e3f2225009fd2b9","__v":42,"version":{"_id":"563b65bd9e3f2225009fd2bf","project":"563b65bd9e3f2225009fd2bc","__v":4,"createdAt":"2015-11-05T14:20:45.639Z","releaseDate":"2015-11-05T14:20:45.639Z","categories":["563b65be9e3f2225009fd2c0","563b6b25e951f60d000b4513","563c239e260dde0d00c5e890","563c2440260dde0d00c5e891"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"4.0.0","version":"4.0"},"parentDoc":null,"project":"563b65bd9e3f2225009fd2bc","category":{"_id":"563b6b25e951f60d000b4513","version":"563b65bd9e3f2225009fd2bf","__v":6,"pages":["563c21fd19ae7b0d0050d45b","563c220c7539dd0d00dbee87","563c2218ac77910d00279fe7","563c2233d8f2d20d00448b4f","563c2376913e650d00b65dbd","563c907319ae7b0d0050d528"],"project":"563b65bd9e3f2225009fd2bc","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-11-05T14:43:49.565Z","from_sync":false,"order":1,"slug":"the-basics","title":"The Basics"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-11-06T03:44:51.474Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"The forms are aims to rethink elegantly creation of forms by transforming each field into its own model, with its own methods and attributes. This means that you can do this sort of stuff \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::horizontal_open()\\n  ->id('MyForm')\\n  ->secure()\\n  ->rules(['name' => 'required'])\\n  ->method('GET');\\n\\n  Form::xlarge_text('name')\\n    ->class('myclass')\\n    ->value('Joseph')\\n    ->required();\\n\\n  Form::textarea('comments')\\n    ->rows(10)->columns(20)\\n    ->autofocus();\\n\\n  Form::actions()\\n    ->large_primary_submit('Submit')\\n    ->large_inverse_reset('Reset');\\n\\nForm::close();\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n## Every time you call a method that doesn't actually exist, Form assumes you're trying to set an attribute and creates it magically. That's why you can do in the above example ***->rows(10)*** ; in case you want to set attributes that contain dashes, just replace them by underscores : **-** ***>data_foo('bar')*** equals **data-foo=\"bar\"**. Now of course in case you want to set an attribute that actually contains an underscore you can always use the fallback method ***setAttribute('data_foo', 'bar')***. You're welcome. \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"GETTING STARTED\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Core Concept\"\n}\n[/block]\nForm is to be used as a View helper – meaning it provides for you a class that you can use directly in your views to output HTML code.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?= Form::open()->method('GET') ?>\\n    <?= Form::text('name')->required() ?>\\n<?= Form::close() ?>\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nIf you're using Twig or other more closed view templating systems, you can still use Form's classes outside \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$form = (string)Form::open()->method('GET');\\n    $form .= Form::text('name')->required();\\n$form .= Form::close();\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"FEATURES\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Out-of-the-box integration to Bootstrap and Foundation\"\n}\n[/block]\nForm recognizes when a horizontal or vertical form is created, and goes the extra mile of wrapping each field in a control group, all behind the scenes. That means that when you type this \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::select('clients')->options($clients, 2)\\n  ->help('Pick some dude')\\n  ->state('warning')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nWhat you actually get is the following output (with Bootstrap)\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<div class=\\\"control-group warning\\\">\\n  <label for=\\\"clients\\\" class=\\\"control-label\\\">Clients</label>\\n  <div class=\\\"controls\\\">\\n    <select id=\\\"clients\\\" name=\\\"clients\\\">\\n      <option value=\\\"0\\\">Mickael</option>\\n      <option value=\\\"1\\\">Joseph</option>\\n      <option value=\\\"2\\\" selected=\\\"selected\\\">Patrick</option>\\n    </select>\\n    <span class=\\\"help-inline\\\">Pick some dude</span>\\n  </div>\\n</div>\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nBy default Form will use Twitter Bootstrap for its syntax but you can select which framework to use with the method ***Form::framework()***. For the moment Form supports ***'TwitterBootstrap', 'ZurbFoundation' ***and*** 'Nude'*** (for no framework).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Turn off Bootstrap syntax\\nForm::framework('Nude');\\n\\n// Turn it on again (MAKE UP YOUR MIND JEEZ)\\nForm::framework('TwitterBootstrap');\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nHere is an example of code for Foundation \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::framework('ZurbFoundation');\\n\\nForm::four_text('foo')->state('error')->help('bar')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nOutputs\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<div class=\\\"error\\\">\\n  <label for=\\\"foo\\\">Foo</label>\\n  <input class=\\\"four\\\" type=\\\"text\\\" name=\\\"foo\\\" id=\\\"foo\\\">\\n  <small>Bar</small>\\n</div>\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Custom Framework\"\n}\n[/block]\nYou may also implement your own framework/way of doing this by setting a custom class for ***Form::framework()*** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Custom framework\\nForm::framework('CustomNameSpace\\\\YourFramework');\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Ties-in with Laravel's Validator\"\n}\n[/block]\nA lot of clutter removed by not having to call the lenghty ***Form::control_group()*** function.\n\nYou woudl not need to manually validate my form and su. \n\nEnters Form's magic helper ***withErrors***; wraps fields into control groups, it goes the distance, and gently check the ***Message*** object for any errors that field might have, and set that error as an ***.help-inline. \n\n**If your render a view on failed validation (no redirection)** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"if($validation->fails()) {\\n  Form::withErrors($validation);\\n  return view('myview');\\n}\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n**If your redirect on failed validation** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"if($validation->fails()) {\\n  return redirect('login')\\n    ->withErrors($validation);\\n}\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nIn the last example you never actually call Form, be it in your controller or in your view. \n\nThat's because when Form opens a form on a page, it will automatically check in Session if there's not an object called ***errors ***and if there is, it will try to use it without requiring you to call anything. \n\nYou can disable Form's automatic errors fetching with the following option : ***Form::config('fetch_errors', false).*** \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"FORM POPULATING\"\n}\n[/block]\nYou can populate a form with value quite easily with the ***Form::populate*** function. \n\nThere is two ways to do that. \n\nThe first way is the usual passing of an array of values.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Will populate the field 'name' with the value 'value'\\nForm::populate( array('name' => 'value') )\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nYou can also populate a form by passing an Eloquent model to it, say you have a Client model.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::populate( Client::find(2) )\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nForm will recognize the model and populate the field with the model's attribute. If here per example our client has a ***name ***set to 'Foo' and a ***firstname ***set to 'Bar', Form will look for fields named 'name' and 'firstname' and fill them respectively with 'Foo' and 'Bar'.\n\nAlternatively you can also populate a specific field after you've populated the whole form (for a relationship per example) by doing this \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::populate($project)\\n\\nForm::populateField('client', $project->client->name)\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nFor the rest of the form, filling fields is basically as easy as doing ***->value('something')***. To generate a list of options for a ***<select> ***you call ***Form::select('foo')->options([array], [facultative: selected value])***. You can also use the results from an Eloquent/Fluent query as options for a select.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::select('foo')->fromQuery(Client::all(), 'name', 'id')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nWhere the second argument is which attribute will be used for the option's text, and the third facultative argument is which attribute will be used for the option's value (defaults to the ***id*** attribute). \n\nForm also does some magic if none of those two arguments are specified. If you pass Eloquent models to Form and don't specify what is to be used as key or value. The Form will obtain the key by using Eloquent's ***get_key()*** method, and use any ***__toString()*** method binded to the model as raw value. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"class Client extends Eloquent\\n{\\n  public static $key = 'code';\\n\\n  public function __toString()\\n  {\\n    return $this->name;\\n  }\\n}\\n\\nForm::select('clients')->fromQuery(Client::all());\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nIs the same as doing this but you know, in less painful and DRYer. This will use each Client's default key, and output the Client's name as the option's label.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<div class=\\\"control-group\\\">\\n  <label for=\\\"foo\\\" class=\\\"control-label\\\">Foo</label>\\n  <div class=\\\"controls\\\">\\n    <select id=\\\"foo\\\" name=\\\"foo\\\">\\n      :::at:::foreach(Client::all() as $client)\\n        @if(Input::get('foo', Input::old('foo')) == $client->code)\\n          <option selected=\\\"selected\\\" value=\\\"{{ $client->code }}\\\">{{ $client->name }}</option>\\n        @else\\n          <option value=\\\"{{ $client->code }}\\\">{{ $client->name }}</option>\\n        @endif\\n      @endforeach\\n    </select>\\n  </div>\\n</div>\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nForm is also able to populate fields with relationships. Now an example is worth a thousand words (excepted if, you know, your example is a thousand words long)\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::populate(Client::find(2))\\n\\n// Will populate with $client->name\\nForm::text('name')\\n\\n// Will populate with $client->store->name\\nForm::text('store.name')\\n\\n// You can go as deep as you need to\\nForm::text('customer.name.adress')\\n\\n// Will populate with the date from all of the client's reservations\\nForm::select('reservations.date')\\n\\n// Which is the same as this ^\\nForm::select('reservations')->fromQuery($client->reservations, 'date')\\n\\n// If you're using a text and not a select, instead of listing the\\n// relationship's models as options, it wil concatenate them\\nForm::text('customers.name') // Will display \\\"name, name, name\\\"\\n\\n// You can rename a field afterwards for easier Input handling\\nForm::text('comment.title')->name('title')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Datalists\"\n}\n[/block]\nDatalists, allows people to get a choice or range of selections or input the selection that they desire. You can simply create a datalist as follows \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::text('clients')->useDatalist($clients)\\n\\n// Or use a Query object, same syntax than fromQuery()\\nForm::text('projects')->useDatalist(Project::all(), 'name')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nYou can also (if you need to) set a custom id on the created datalist by doing ***Form::text('foo')->list('myId')->useDatalist()***. \n\nFrom there it will automatically generate the corresponding ***<datalist>*** and link it by ***id ***to that field. \n\nThe text input will get populated by the values in your array, while still letting people type whatever they would like.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Live validation\"\n}\n[/block]\nAll modern browsers support instant validation via HTML attributes —there is no need for Javascript nor script nor polyfill. \n\nThere are a few attributes that can allow you to conduct instant validation, ***pattern, required, max/min ***to name a few. \n\nWhen you validate your POST data with that little $rules array. You would be able to pass that array to your form and let it transcribe your rules into real-live validation\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::open()->rules(array(\\n  'name'     => 'required|max:20|alpha',\\n  'age'      => 'between:18,24',\\n  'email'    => 'email',\\n  'show'     => 'in:batman,spiderman',\\n  'random'   => 'match:/[a-zA-Z]+/',\\n  'birthday' => 'before:1968-12-03',\\n  'avatar'   => 'image',\\n));\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThe Form will look for fields that match the keys and apply the best it can those rules. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<input name=\\\"name\\\"      type=\\\"text\\\"   required maxlength=\\\"20\\\" pattern=\\\"[a-zA-Z]+\\\" />\\n<input name=\\\"age\\\"       type=\\\"number\\\" min=\\\"18\\\" max=\\\"24\\\" />\\n<input name=\\\"email\\\"     type=\\\"email\\\" />\\n<input name=\\\"show\\\"      type=\\\"text\\\"   pattern=\\\"^(batman|spiderman)$\\\" />\\n<input name=\\\"random\\\"    type=\\\"text\\\"   pattern=\\\"[a-zA-Z]+\\\" />\\n<input name=\\\"birthday\\\"  type=\\\"date\\\"   max=\\\"1968-12-03\\\" />\\n<input name=\\\"avatar\\\"    type=\\\"file\\\"   accept=\\\"image/jpeg,image/png,image/gif,image/bmp\\\" />\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nNote that you can always add custom rules the way you'd add any attributes, since the pattern attribute uses a Regex.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::number('age')->min(18)\\n\\nForm::text('client_code')->pattern('[a-z]{4}[0-9]{2}')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nBootstrap recognizes live validation, if you type something that doesn't match the ***alpha ***pattern in your name field, it will automatically turn red just like when your control group is set to ***error***. \n\nYou can also, mid-course, manually set the state of a control group — that's a feature of course available only if you're using either Bootstrap or Foundation. You can use any of the control group states which include*** success, warning, error ***and ***info***.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Files handling\"\n}\n[/block]\nIn Form like in Laravel you can create a simple file field with ***Form::file***. What's new, is you can also create a multiple files field by calling ***Form::files*** which which will generate ***<input type=\"file\" name=\"foo[]\" multiple />.*** \n\nOne of the special method is the*** ->accept() ***with which you can do the following\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Use a shortcut (image, video or audio)\\nForm::files('avatar')->accept('image')\\n\\n// Use an extension which will be converted to MIME by Laravel\\nForm::files('avatar')->accept('gif', 'jpg')\\n\\n// Or directly use a MIME\\nForm::files('avatar')->accept('image/jpeg', 'image/png')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nYou can also set a maximum size easily by using either bits or bytes\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::file('foo')->max(2, 'MB')\\nForm::file('foo')->max(400, 'Kb')\\nForm::file('foo')->max(1, 'TB')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis will create an hidden ***MAX_FILE_SIZE*** field with the correct value in bytes.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Checkboxes and Radios\"\n}\n[/block]\nWith Form it's all a little easier to validate all the respective Checkboxes and radios. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Create a one-off checkbox\\nForm::checkbox('checkme')\\n\\n// Create a one-off checkbox with a text, and check it\\nForm::checkbox('checkme')\\n  ->text('YO CHECK THIS OUT')\\n  ->check()\\n\\n// Create four related checkboxes\\nForm::checkboxes('checkme')\\n  ->checkboxes('first', 'second', 'third', 'fourth')\\n\\n// Create related checkboxes, and inline them\\nForm::checkboxes('checkme')\\n  ->checkboxes($checkboxes)->inline()\\n\\n// Everything that works on a checkbox also works on a radio element\\nForm::radios('radio')\\n  ->radios(array('label' => 'name', 'label' => 'name'))\\n  ->stacked()\\n\\n// Stacked and inline can also be called as magic methods\\nForm::inline_checkboxes('foo')->checkboxes('foo', 'bar')\\nForm::stacked_radios('foo')->radios('foo', 'bar')\\n\\n// Set which checkables are checked or not in one move\\nForm::checkboxes('level')\\n  ->checkboxes(0, 1, 2)\\n  ->check(array('level_0' => true, 'level_1' => false, 'level_2' => true))\\n\\n// Fine tune checkable elements\\nForm::radios('radio')\\n  ->radios(array(\\n    'label' => array('name' => 'foo', 'value' => 'bar', 'data-foo' => 'bar'),\\n    'label' => array('name' => 'foo', 'value' => 'bar', 'data-foo' => 'bar'),\\n  ))\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n**Important point** : The form gives you an option to force the pushing of checkboxes. \n\nThat's when your checkboxes still pop up in your POST data even when they're unchecked. \n\nYou can further change what value an unchecked checkbox possesses in the POST array via the unchecked_value option.\n\nWhen creating checkables via the checkboxes/radios() method, by default for each checkable name attribute it will use the original name you specified and append it a number (here in our exemple it would be <input type=\"checkbox\" name=\"checkme_2\">). It also repopulates it, meaning a checked input will stay checked on submit.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Localization helpers\"\n}\n[/block]\nIf you would want to work on multilingual projects, the Form is also capable of helping. \n\nBy default, when creating a field, if no label is specified the Form will use the field name by default. It will try and translate it automatically. \n\nThe same applied towards checkboxes labels, help texts and form legends. \n\nThis can be repreented through the following\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// This\\nForm::label(__('validation.attributes.name'))\\nForm::text('name', __('validation.attributes.name'))\\nForm::text('name')->inlineHelp(__('help.name'))\\nForm::checkbox('rules')->text(__('my.translation'))\\n<legend>{{ __('validation.attributes.mylegend') }}</legend>\\n\\n// Is the same as this\\nForm::label('name')\\nForm::text('name')\\nForm::text('name')->inlineHelp('help.name')\\nForm::checkbox('rules')->text('my.translation')\\nForm::legend('mylegend')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThe Form will first try to translate the string in itself, ie ***my.text*** will return ***__('my.text')*** and if that fails, it will look for it in a fallback place. \n\nYou can further set the Form to look for translations by changing the following variable : ***Form::config('translate_from', [boolean])*** (defaults to ***validation.attributes***). \n\nThis must be an array.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Notes on setting field values\"\n}\n[/block]\nAll the form classes encounter a problem at one point : \n\nTo populate your field, Form set the following priorities to found values\n\n1. The ***->forceValue()*** method wins over everything – it's a special branch of ***->value()*** created to force a value in a field no matter what happens\n\n2. Next is POST data – if a user just typed something in a field, chances are this is what they want to see in it next time\n\n3. Then any values set via ***Form::text()->populate()***, so you can override any global population on a per-element basis.\n\n4. Then any values set via ***Form::populate()*** – that means that if you're editing something or are repopulating with some value, it can be overwritten with ***forceValue***\n\n5. Finally the classic ***->value()*** gets the least priority – it is created for minimum and default field values and thus gets overwritten by population and POST data\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Anatomy of Form\"\n}\n[/block]\nBare with me, there are a lot of classes but it all makes sense once you read what they do :\n\n**Form** : The main class, mostly handles configuration and interactions between the form parts\n**FormServiceProvider** : The Service Provider for Laravel 4\n**Helpers** : A set of static helpers used troughout the library\n**Dispatch **: Catches the call you do the Form facade and dispatches them to the right classes\n**LiveValidation **: This Handles live validation of fields and translation of rules into attributes\n**Populator **: A value container from which Form gets/sets the fields values\n**Traits**\n**Checkable **: Common methods and properties to radios and checkboxes\n**Field **: Common methods and properties to all fields\n**FormObject **: A base object extended by the traits above, handles dynamic attributes and stuff\n**Framework **: Common methods and properties to all frameworks\n**Interfaces **: Required methods by all fields an frameworks\n**FieldInterface**\n**FrameworkInterface**\n**Framework **: These classes generate the right markup according to the framework in use\n**Nude**\n**TwitterBootstrap**\n**ZurbFoundation**\n**Form **: All the classes underneath handle the actual markup and elements of a form\n**Actions **: Handles the actions blocks where submit buttons and all are found\n**Elements **: Various form elements that are neither fields nor actions (legends, etc)\n**Form **: Handles the form opening and closing and the methods that go with it\n**Group **: Wraps fields and provide field states, errors fetching and such\n**Fields **: The field classes, each handle one kind of field. The names say it all\n**Button**\n**Checkbox**\n**File**\n**Hidden**\n**Input**\n**Radio**\n**Select**\n**Textarea**\n**Uneditable**\n**Facades **: Various entry points that smooth out the experience across environments\n**Agnostic **: The base facade used by Form outside of any framework\n**FormBuilder **: Common methods and building blocks for all facades to use\n**Illuminate **: The Laravel 4 facade, hooks up Form to the various components (localization etc)\n**LaravelThree **: The Laravel 3 facade, hooks up Form to the various components (localization etc)\n**Legacy **: A set of redirector classes that unify the interface between Laravel 3 and 4\n**Config**\n**Redirector**\n**Session**\n**Translator** \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Description of each method\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Form\\\\Form\"\n}\n[/block]\nThis class is the main class - it is your interface for everything in Form. \n\nNow of course, Form makes you interact with its subclasses which means you can not only use its methods but the methods of each class used by Form.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Options\"\n}\n[/block]\nThis is a set of options that can be set to modify Form's behavior.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::setOption('translate_from', [string]) ('validation.attributes')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nBy default Form tries to translate most labels, legends and help texts. For that it first tries to translate the string passed as is, and then it tries to look in a special place that can be defined with this variable - defaulting to 'validation.attributes.mykey'.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::setOption('required_class', [string]) ('required')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nA class to add to fields that are set as required.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::setOption('default_form_type', [horizontal|vertical|inline|search]) ('horizontal')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nBy default when you call ***Form::open*** a fallback form type gets assigned to the form – this is the option that says which one is that type. It can be any of those values, or null if you want don't want to use Bootstrap's form classes.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::setOption('fetch_errors', [boolean]) (true)\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nWhenever you call the ***open*** method, if this option is set to true, Form will look into the Session array for a ***Message*** objects that would have been created by the -***>with_errors()*** method of ***Redirect***. Which means that if on failed validation you do ***Redirect::to()->with_errors()***, Form will automatically fetch said errors and display them on the corresponding fields without having to type anything.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::setOption('automatic_label', [boolean]) (true)\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nAllows the user to turn on or off the automatic labeling feature. When it's on, if you give per example ***foo*** as a field name and no label, Form will assume ***foo*** is also to be used as label. Form will then attempt to translate it, capitalize it, and use it as label. With this option turned off, if no label is specific, no label tag will be printed out.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::setOption('live_validation', [boolean]) (true)\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nWhether Form should try to apply Laravel's Validator rules as live validation attributes.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::setOption('push_checkboxes', [boolean]) (true)\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nWhether checkboxes should always be present in the POST data, no matter if you checked them or not\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::setOption('TwitterBootstrap3.labelWidths', array('large' => 2, 'small' => 3)) ?>\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nSet the Bootstrap label width for your form.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Helpers\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::populate([array|Eloquent])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nPopulates the fields with an array of values or an Eloquent object.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::withErrors([Validator])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nIf you have an ***$errors*** variable from a failed validation, the Form will automatically fetch it from Session and set the corresponding fields as incorrect and display the error message right next to them. This is if you're calling ***withErrors*** in your view. If you're in the controller, you can simply pass the ***$validator*** object to Form and it will work just the same.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::withRules([array])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nLet you pass an array of Laravel rules to Form, to let it try and apply those rules live with HTML attributes such as ***pattern***, ***maxlength***, etc.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::framework([TwitterBootstrap3|ZurbFoundation5|null])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nSelect which CSS framework Form should use for its syntax – each gives you more or less access to the available methods. Per example you can't use Bootstrap's ***->blockHelp*** method while using Zurb, etc.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$error = Form::getErrors([string])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis is equivalent to\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$error = isset($errors) ? $errors->first('field') : null.\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Form builders\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::legend([string])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis opens a Bootstrap ***legend>*** tag in your form – the string passed to Form can be a translation index since Form will attempt to translate it.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::open()\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThe ***open*** method mirrors Laravel's, which means you can refer to the doc for it on Laravel's website. But it also support the magic methods introduced by Bootstrapper for backward compatibility :\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::horizontal_open()\\nForm::secure_open()\\nForm::open_for_files()\\nForm::secure_vertical_open_for_files()\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nYou can mix it up however you want as long as each block remain intact \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::close()\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis is pretty straightforward, simply prints out a </form> tag. It contains no argument or anything.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::actions([string, ...])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nCreates a ***<div class='form-actions'>*** tag to wrap your submit/reset/back/etc buttons. \n\nTo output multiple buttons simply use multiple arguments\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Button class from Bootstrapper\\nForm::actions( Button::submit('Submit'), Button::reset('Reset') )\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Field Builders\"\n}\n[/block]\nThis is the one class you'll be using the two thirds of the time\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::[classes]_[field]\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis method analyze whatever unknown method you're trying to call and creates a field with it. \n\nIt decomposes it as [classes]_[field] or [field]. As classes you can call all Bootstrap classes working on fields : **span1** to **span12** and **mini** to **xxlarge**\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Form\\\\Field\"\n}\n[/block]\nThis class is what you actually get when you create a field, which means the method listed underneath are only accessible as chained methods after a field was created. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Here you're using Form\\nForm::populate($project)\\n\\n// Here you're actually using the Field class wrapped in Form\\nForm::text('foo')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nA Form class stops being a field the second that field is printed out. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$textField = Form::text('foo');\\n$textField->class('myclass')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nBut can't do this\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"echo Form::text('foo')\\nForm::class('myclass')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Interactions with the attributes\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::text('foo')->addClass([string])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nAdds a class to the current field without overwriting any existing one. \n\nThis does differs front ***->class()*** will — just like any attribute setter — overwrite any existing value\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::text('foo')->forceValue([string])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis forces the field value to a particular value, ignoring both POST data and ***Form::populate()*** values.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::text('foo')->value([string])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis sets a default value for a field — a text present in it but that will get overwritten by calls to ***Form::populate*** or POST data.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::text('foo')->[attribute]([value])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis sets the value of any attribute. Attributes containing dashes have to be replaced with an underscore, so that you'd call ***data_foo('bar')*** to set ***data-foo=\"bar\"***.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::text('text')->setAttribute([string], [string])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis can be used as a fallback to the magic methods, if you really want to set an attribute that contains an underscore.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::text('foo')->setAttributes([associative array])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis code allows you to mass-set a couple of attributes with an array. \n\nThe following examples do the exact same thing.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::text('foo')->class('foo')->foo('bar')\\n\\nForm::text('foo')->setAttributes(array( 'class' => 'foo', 'foo' => 'bar' ))\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThe second method is not the cleanest per say but it is still useful if you have to set the same attributes for a group of fields. \n\nYou can then just create an array with the attributes you want and assign it to each field in order to stay DRY.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::text('foo')->label([string])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis sets the label of a field to a string. \n\nIf you're using Bootstrap this would have a specific meaning, since the label that will be created will automatically have the class control-label.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::text('foo')->addGroupClass('bar')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis adds specified class attributes to the parent control-group.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Helpers\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$textField = Form::text('foo')->require()\\n$textField = $textField->isRequired() // Returns \\\"true\\\"\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis checks if a field has been set to required, be it by yourself or when transposing Laravel rules.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Form\\\\Checkable\"\n}\n[/block]\nThe Checkable is a subset of Field. \n\nThis means all methods available with the Field are available with Checkable. The latter just offers a few more methods related to radios and checkboxes.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::radios('foo')->inline()\\nForm::checkboxes('foo')->stacked()\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis would set the current radios and checkboxes as inline, or stacked (vertical)\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::checkbox('foo')->text('bar')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nIf you're printing only a single checkbox/radio, \n\nit's easier to use this method to set the text that will be appended to it.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::checkbox('foo')->check()\\nForm::radio('foo')->check()\\n\\nForm::checkboxes('foo')->checkboxes('foo', 'bar')->check('foo_0')\\n\\nForm::radios('foo')->checkboxes('foo', 'bar')->check(0)\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThe check method allows you to check a one-off checkable element, or to check one in a group of checkable elements. \n\nFor single elements you can just call check() without arguments – but when you're using a group you would need to specify which element is going to be checked. \n\nThis is done differently if you're creating radios or checkboxes. \n\nThis is because checkboxes can only be differentiated by their field name, while radio elements can only be differentiated by their value. The checkboxes you specify the name of the one you want to see checked, and for radios you specify its value.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Form\\\\ControlGroup\"\n}\n[/block]\nHelpers and methods related to Bootstrap's control groups. If you set the ***$useBootstrap*** option to false earlier, this class is not accessible, nor are any of its methods.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::text('foo')->state([error|warning|info|success])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis set the state of a control group to a particular Bootstrap class.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::text('foo')->inlineHelp([string])\\nForm::text('foo')->blockHelp([string])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThis further adds an inline/block help text to the current field. \n\nBoth can be called (meaning you can have both an inline and a block text) but can only be called once (which means if you call inlineHelp twice the latter will overwrite whatever you typed in the first one).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::text('foo')->append([string, ...])\\nForm::text('foo')->prepend([string, ...])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nPrepends one or more icons/text/buttons to the current field. Those functions use ***func_get_args()*** so you can per example \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::text('foo')->prepend('@', '$')\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Form\\\\Fields\\\\Input\"\n}\n[/block]\nAll classes related to Input-type fields.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::text('foo')->useDatalist([array])\\n\\nForm::text('foo')->useDatalist([Query], [string], [string (id)])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nCreates a ***<datalist>*** tag and links it to the field in order to create a select/text mix.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Form\\\\Fields\\\\Select\"\n}\n[/block]\nAll classes related to Select-type fields (select, multiselect, etc)\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::select('foo')->options([array], [selected])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nPopulates a ***<select>*** field with an array of options, where key will be the option's value and value will be its text. It sounds retarted explained like that but it means the following :\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::select('clients')->options(array(\\n    1  => 'Max',\\n    3  => 'Clémence',\\n    12 => 'Jean Valjean'\\n));\\n\\n<select name=\\\"foo\\\">\\n    <option value=\\\"1\\\">Max</option>\\n    <option value=\\\"3\\\">Clémence</option>\\n    <option value=\\\"12\\\">Jean Valjean</option>\\n</select>\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nWhich looks really natural : you select a client's name and get it's ID in return. The second parameters allows to preselect one option, per example if in the above example we'd done -***>options($clients, 3)*** then Clémence would have been selected.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::select('foo')->select(3)\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nAlias for ***->value()***, selects an option.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::select('foo')->fromQuery([array], [string], [string (id)])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nPopulates a ***<select>*** field with the results of a Fluent/Eloquent query. Second argument is the attribute used by Form for the options text, third argument is the attribute used by Form for the options value (defaults to the ***id*** attribute). Second argument defaults to the model's ***__toString()*** method, thirds defaults to the model's ***get_key()*** method.\n\nAlternative use ***fromQuery*** for ***Form::select***\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::select('foo')->fromQuery([array], [callable], [array])\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nSample:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::select('foo')->fromQuery(\\n    $collection,\\n    function($model) {\\n        return $model->id . $model->name;//option text\\n    },\\n    [//array option attributes\\n        'value' => 'id',\\n        'data-test' => function($model) {\\n            return $model->test_field;\\n        }\\n    ]\\n);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nPossible mixed use.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Form::select('foo')->placeholder('Select one option...')\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nCreate a ghost option set as disabled by default to serve as placeholder for the select.","excerpt":"Manages form controls.","slug":"form","type":"basic","title":"Form"}

Form

Manages form controls.

The forms are aims to rethink elegantly creation of forms by transforming each field into its own model, with its own methods and attributes. This means that you can do this sort of stuff [block:code] { "codes": [ { "code": "Form::horizontal_open()\n ->id('MyForm')\n ->secure()\n ->rules(['name' => 'required'])\n ->method('GET');\n\n Form::xlarge_text('name')\n ->class('myclass')\n ->value('Joseph')\n ->required();\n\n Form::textarea('comments')\n ->rows(10)->columns(20)\n ->autofocus();\n\n Form::actions()\n ->large_primary_submit('Submit')\n ->large_inverse_reset('Reset');\n\nForm::close();", "language": "php" } ] } [/block] ## Every time you call a method that doesn't actually exist, Form assumes you're trying to set an attribute and creates it magically. That's why you can do in the above example ***->rows(10)*** ; in case you want to set attributes that contain dashes, just replace them by underscores : **-** ***>data_foo('bar')*** equals **data-foo="bar"**. Now of course in case you want to set an attribute that actually contains an underscore you can always use the fallback method ***setAttribute('data_foo', 'bar')***. You're welcome. [block:api-header] { "type": "basic", "title": "GETTING STARTED" } [/block] [block:api-header] { "type": "basic", "title": "Core Concept" } [/block] Form is to be used as a View helper – meaning it provides for you a class that you can use directly in your views to output HTML code. [block:code] { "codes": [ { "code": "<?= Form::open()->method('GET') ?>\n <?= Form::text('name')->required() ?>\n<?= Form::close() ?>", "language": "php" } ] } [/block] If you're using Twig or other more closed view templating systems, you can still use Form's classes outside [block:code] { "codes": [ { "code": "$form = (string)Form::open()->method('GET');\n $form .= Form::text('name')->required();\n$form .= Form::close();", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "FEATURES" } [/block] [block:api-header] { "type": "basic", "title": "Out-of-the-box integration to Bootstrap and Foundation" } [/block] Form recognizes when a horizontal or vertical form is created, and goes the extra mile of wrapping each field in a control group, all behind the scenes. That means that when you type this [block:code] { "codes": [ { "code": "Form::select('clients')->options($clients, 2)\n ->help('Pick some dude')\n ->state('warning')", "language": "php" } ] } [/block] What you actually get is the following output (with Bootstrap) [block:code] { "codes": [ { "code": "<div class=\"control-group warning\">\n <label for=\"clients\" class=\"control-label\">Clients</label>\n <div class=\"controls\">\n <select id=\"clients\" name=\"clients\">\n <option value=\"0\">Mickael</option>\n <option value=\"1\">Joseph</option>\n <option value=\"2\" selected=\"selected\">Patrick</option>\n </select>\n <span class=\"help-inline\">Pick some dude</span>\n </div>\n</div>", "language": "php" } ] } [/block] By default Form will use Twitter Bootstrap for its syntax but you can select which framework to use with the method ***Form::framework()***. For the moment Form supports ***'TwitterBootstrap', 'ZurbFoundation' ***and*** 'Nude'*** (for no framework). [block:code] { "codes": [ { "code": "// Turn off Bootstrap syntax\nForm::framework('Nude');\n\n// Turn it on again (MAKE UP YOUR MIND JEEZ)\nForm::framework('TwitterBootstrap');", "language": "php" } ] } [/block] Here is an example of code for Foundation [block:code] { "codes": [ { "code": "Form::framework('ZurbFoundation');\n\nForm::four_text('foo')->state('error')->help('bar')", "language": "php" } ] } [/block] Outputs [block:code] { "codes": [ { "code": "<div class=\"error\">\n <label for=\"foo\">Foo</label>\n <input class=\"four\" type=\"text\" name=\"foo\" id=\"foo\">\n <small>Bar</small>\n</div>", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "Custom Framework" } [/block] You may also implement your own framework/way of doing this by setting a custom class for ***Form::framework()*** [block:code] { "codes": [ { "code": "// Custom framework\nForm::framework('CustomNameSpace\\YourFramework');", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "Ties-in with Laravel's Validator" } [/block] A lot of clutter removed by not having to call the lenghty ***Form::control_group()*** function. You woudl not need to manually validate my form and su. Enters Form's magic helper ***withErrors***; wraps fields into control groups, it goes the distance, and gently check the ***Message*** object for any errors that field might have, and set that error as an ***.help-inline. **If your render a view on failed validation (no redirection)** [block:code] { "codes": [ { "code": "if($validation->fails()) {\n Form::withErrors($validation);\n return view('myview');\n}", "language": "php" } ] } [/block] **If your redirect on failed validation** [block:code] { "codes": [ { "code": "if($validation->fails()) {\n return redirect('login')\n ->withErrors($validation);\n}", "language": "php" } ] } [/block] In the last example you never actually call Form, be it in your controller or in your view. That's because when Form opens a form on a page, it will automatically check in Session if there's not an object called ***errors ***and if there is, it will try to use it without requiring you to call anything. You can disable Form's automatic errors fetching with the following option : ***Form::config('fetch_errors', false).*** [block:api-header] { "type": "basic", "title": "FORM POPULATING" } [/block] You can populate a form with value quite easily with the ***Form::populate*** function. There is two ways to do that. The first way is the usual passing of an array of values. [block:code] { "codes": [ { "code": "// Will populate the field 'name' with the value 'value'\nForm::populate( array('name' => 'value') )", "language": "php" } ] } [/block] You can also populate a form by passing an Eloquent model to it, say you have a Client model. [block:code] { "codes": [ { "code": "Form::populate( Client::find(2) )", "language": "php" } ] } [/block] Form will recognize the model and populate the field with the model's attribute. If here per example our client has a ***name ***set to 'Foo' and a ***firstname ***set to 'Bar', Form will look for fields named 'name' and 'firstname' and fill them respectively with 'Foo' and 'Bar'. Alternatively you can also populate a specific field after you've populated the whole form (for a relationship per example) by doing this [block:code] { "codes": [ { "code": "Form::populate($project)\n\nForm::populateField('client', $project->client->name)", "language": "php" } ] } [/block] For the rest of the form, filling fields is basically as easy as doing ***->value('something')***. To generate a list of options for a ***<select> ***you call ***Form::select('foo')->options([array], [facultative: selected value])***. You can also use the results from an Eloquent/Fluent query as options for a select. [block:code] { "codes": [ { "code": "Form::select('foo')->fromQuery(Client::all(), 'name', 'id')", "language": "php" } ] } [/block] Where the second argument is which attribute will be used for the option's text, and the third facultative argument is which attribute will be used for the option's value (defaults to the ***id*** attribute). Form also does some magic if none of those two arguments are specified. If you pass Eloquent models to Form and don't specify what is to be used as key or value. The Form will obtain the key by using Eloquent's ***get_key()*** method, and use any ***__toString()*** method binded to the model as raw value. [block:code] { "codes": [ { "code": "class Client extends Eloquent\n{\n public static $key = 'code';\n\n public function __toString()\n {\n return $this->name;\n }\n}\n\nForm::select('clients')->fromQuery(Client::all());", "language": "php" } ] } [/block] Is the same as doing this but you know, in less painful and DRYer. This will use each Client's default key, and output the Client's name as the option's label. [block:code] { "codes": [ { "code": "<div class=\"control-group\">\n <label for=\"foo\" class=\"control-label\">Foo</label>\n <div class=\"controls\">\n <select id=\"foo\" name=\"foo\">\n @foreach(Client::all() as $client)\n @if(Input::get('foo', Input::old('foo')) == $client->code)\n <option selected=\"selected\" value=\"{{ $client->code }}\">{{ $client->name }}</option>\n @else\n <option value=\"{{ $client->code }}\">{{ $client->name }}</option>\n @endif\n @endforeach\n </select>\n </div>\n</div>", "language": "php" } ] } [/block] Form is also able to populate fields with relationships. Now an example is worth a thousand words (excepted if, you know, your example is a thousand words long) [block:code] { "codes": [ { "code": "Form::populate(Client::find(2))\n\n// Will populate with $client->name\nForm::text('name')\n\n// Will populate with $client->store->name\nForm::text('store.name')\n\n// You can go as deep as you need to\nForm::text('customer.name.adress')\n\n// Will populate with the date from all of the client's reservations\nForm::select('reservations.date')\n\n// Which is the same as this ^\nForm::select('reservations')->fromQuery($client->reservations, 'date')\n\n// If you're using a text and not a select, instead of listing the\n// relationship's models as options, it wil concatenate them\nForm::text('customers.name') // Will display \"name, name, name\"\n\n// You can rename a field afterwards for easier Input handling\nForm::text('comment.title')->name('title')", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "Datalists" } [/block] Datalists, allows people to get a choice or range of selections or input the selection that they desire. You can simply create a datalist as follows [block:code] { "codes": [ { "code": "Form::text('clients')->useDatalist($clients)\n\n// Or use a Query object, same syntax than fromQuery()\nForm::text('projects')->useDatalist(Project::all(), 'name')", "language": "php" } ] } [/block] You can also (if you need to) set a custom id on the created datalist by doing ***Form::text('foo')->list('myId')->useDatalist()***. From there it will automatically generate the corresponding ***<datalist>*** and link it by ***id ***to that field. The text input will get populated by the values in your array, while still letting people type whatever they would like. [block:api-header] { "type": "basic", "title": "Live validation" } [/block] All modern browsers support instant validation via HTML attributes —there is no need for Javascript nor script nor polyfill. There are a few attributes that can allow you to conduct instant validation, ***pattern, required, max/min ***to name a few. When you validate your POST data with that little $rules array. You would be able to pass that array to your form and let it transcribe your rules into real-live validation [block:code] { "codes": [ { "code": "Form::open()->rules(array(\n 'name' => 'required|max:20|alpha',\n 'age' => 'between:18,24',\n 'email' => 'email',\n 'show' => 'in:batman,spiderman',\n 'random' => 'match:/[a-zA-Z]+/',\n 'birthday' => 'before:1968-12-03',\n 'avatar' => 'image',\n));", "language": "php" } ] } [/block] The Form will look for fields that match the keys and apply the best it can those rules. [block:code] { "codes": [ { "code": "<input name=\"name\" type=\"text\" required maxlength=\"20\" pattern=\"[a-zA-Z]+\" />\n<input name=\"age\" type=\"number\" min=\"18\" max=\"24\" />\n<input name=\"email\" type=\"email\" />\n<input name=\"show\" type=\"text\" pattern=\"^(batman|spiderman)$\" />\n<input name=\"random\" type=\"text\" pattern=\"[a-zA-Z]+\" />\n<input name=\"birthday\" type=\"date\" max=\"1968-12-03\" />\n<input name=\"avatar\" type=\"file\" accept=\"image/jpeg,image/png,image/gif,image/bmp\" />", "language": "php" } ] } [/block] Note that you can always add custom rules the way you'd add any attributes, since the pattern attribute uses a Regex. [block:code] { "codes": [ { "code": "Form::number('age')->min(18)\n\nForm::text('client_code')->pattern('[a-z]{4}[0-9]{2}')", "language": "php" } ] } [/block] Bootstrap recognizes live validation, if you type something that doesn't match the ***alpha ***pattern in your name field, it will automatically turn red just like when your control group is set to ***error***. You can also, mid-course, manually set the state of a control group — that's a feature of course available only if you're using either Bootstrap or Foundation. You can use any of the control group states which include*** success, warning, error ***and ***info***. [block:api-header] { "type": "basic", "title": "Files handling" } [/block] In Form like in Laravel you can create a simple file field with ***Form::file***. What's new, is you can also create a multiple files field by calling ***Form::files*** which which will generate ***<input type="file" name="foo[]" multiple />.*** One of the special method is the*** ->accept() ***with which you can do the following [block:code] { "codes": [ { "code": "// Use a shortcut (image, video or audio)\nForm::files('avatar')->accept('image')\n\n// Use an extension which will be converted to MIME by Laravel\nForm::files('avatar')->accept('gif', 'jpg')\n\n// Or directly use a MIME\nForm::files('avatar')->accept('image/jpeg', 'image/png')", "language": "php" } ] } [/block] You can also set a maximum size easily by using either bits or bytes [block:code] { "codes": [ { "code": "Form::file('foo')->max(2, 'MB')\nForm::file('foo')->max(400, 'Kb')\nForm::file('foo')->max(1, 'TB')", "language": "php" } ] } [/block] This will create an hidden ***MAX_FILE_SIZE*** field with the correct value in bytes. [block:api-header] { "type": "basic", "title": "Checkboxes and Radios" } [/block] With Form it's all a little easier to validate all the respective Checkboxes and radios. [block:code] { "codes": [ { "code": "// Create a one-off checkbox\nForm::checkbox('checkme')\n\n// Create a one-off checkbox with a text, and check it\nForm::checkbox('checkme')\n ->text('YO CHECK THIS OUT')\n ->check()\n\n// Create four related checkboxes\nForm::checkboxes('checkme')\n ->checkboxes('first', 'second', 'third', 'fourth')\n\n// Create related checkboxes, and inline them\nForm::checkboxes('checkme')\n ->checkboxes($checkboxes)->inline()\n\n// Everything that works on a checkbox also works on a radio element\nForm::radios('radio')\n ->radios(array('label' => 'name', 'label' => 'name'))\n ->stacked()\n\n// Stacked and inline can also be called as magic methods\nForm::inline_checkboxes('foo')->checkboxes('foo', 'bar')\nForm::stacked_radios('foo')->radios('foo', 'bar')\n\n// Set which checkables are checked or not in one move\nForm::checkboxes('level')\n ->checkboxes(0, 1, 2)\n ->check(array('level_0' => true, 'level_1' => false, 'level_2' => true))\n\n// Fine tune checkable elements\nForm::radios('radio')\n ->radios(array(\n 'label' => array('name' => 'foo', 'value' => 'bar', 'data-foo' => 'bar'),\n 'label' => array('name' => 'foo', 'value' => 'bar', 'data-foo' => 'bar'),\n ))", "language": "php" } ] } [/block] **Important point** : The form gives you an option to force the pushing of checkboxes. That's when your checkboxes still pop up in your POST data even when they're unchecked. You can further change what value an unchecked checkbox possesses in the POST array via the unchecked_value option. When creating checkables via the checkboxes/radios() method, by default for each checkable name attribute it will use the original name you specified and append it a number (here in our exemple it would be <input type="checkbox" name="checkme_2">). It also repopulates it, meaning a checked input will stay checked on submit. [block:api-header] { "type": "basic", "title": "Localization helpers" } [/block] If you would want to work on multilingual projects, the Form is also capable of helping. By default, when creating a field, if no label is specified the Form will use the field name by default. It will try and translate it automatically. The same applied towards checkboxes labels, help texts and form legends. This can be repreented through the following [block:code] { "codes": [ { "code": "// This\nForm::label(__('validation.attributes.name'))\nForm::text('name', __('validation.attributes.name'))\nForm::text('name')->inlineHelp(__('help.name'))\nForm::checkbox('rules')->text(__('my.translation'))\n<legend>{{ __('validation.attributes.mylegend') }}</legend>\n\n// Is the same as this\nForm::label('name')\nForm::text('name')\nForm::text('name')->inlineHelp('help.name')\nForm::checkbox('rules')->text('my.translation')\nForm::legend('mylegend')", "language": "php" } ] } [/block] The Form will first try to translate the string in itself, ie ***my.text*** will return ***__('my.text')*** and if that fails, it will look for it in a fallback place. You can further set the Form to look for translations by changing the following variable : ***Form::config('translate_from', [boolean])*** (defaults to ***validation.attributes***). This must be an array. [block:api-header] { "type": "basic", "title": "Notes on setting field values" } [/block] All the form classes encounter a problem at one point : To populate your field, Form set the following priorities to found values 1. The ***->forceValue()*** method wins over everything – it's a special branch of ***->value()*** created to force a value in a field no matter what happens 2. Next is POST data – if a user just typed something in a field, chances are this is what they want to see in it next time 3. Then any values set via ***Form::text()->populate()***, so you can override any global population on a per-element basis. 4. Then any values set via ***Form::populate()*** – that means that if you're editing something or are repopulating with some value, it can be overwritten with ***forceValue*** 5. Finally the classic ***->value()*** gets the least priority – it is created for minimum and default field values and thus gets overwritten by population and POST data [block:api-header] { "type": "basic", "title": "Anatomy of Form" } [/block] Bare with me, there are a lot of classes but it all makes sense once you read what they do : **Form** : The main class, mostly handles configuration and interactions between the form parts **FormServiceProvider** : The Service Provider for Laravel 4 **Helpers** : A set of static helpers used troughout the library **Dispatch **: Catches the call you do the Form facade and dispatches them to the right classes **LiveValidation **: This Handles live validation of fields and translation of rules into attributes **Populator **: A value container from which Form gets/sets the fields values **Traits** **Checkable **: Common methods and properties to radios and checkboxes **Field **: Common methods and properties to all fields **FormObject **: A base object extended by the traits above, handles dynamic attributes and stuff **Framework **: Common methods and properties to all frameworks **Interfaces **: Required methods by all fields an frameworks **FieldInterface** **FrameworkInterface** **Framework **: These classes generate the right markup according to the framework in use **Nude** **TwitterBootstrap** **ZurbFoundation** **Form **: All the classes underneath handle the actual markup and elements of a form **Actions **: Handles the actions blocks where submit buttons and all are found **Elements **: Various form elements that are neither fields nor actions (legends, etc) **Form **: Handles the form opening and closing and the methods that go with it **Group **: Wraps fields and provide field states, errors fetching and such **Fields **: The field classes, each handle one kind of field. The names say it all **Button** **Checkbox** **File** **Hidden** **Input** **Radio** **Select** **Textarea** **Uneditable** **Facades **: Various entry points that smooth out the experience across environments **Agnostic **: The base facade used by Form outside of any framework **FormBuilder **: Common methods and building blocks for all facades to use **Illuminate **: The Laravel 4 facade, hooks up Form to the various components (localization etc) **LaravelThree **: The Laravel 3 facade, hooks up Form to the various components (localization etc) **Legacy **: A set of redirector classes that unify the interface between Laravel 3 and 4 **Config** **Redirector** **Session** **Translator** [block:api-header] { "type": "basic", "title": "Description of each method" } [/block] [block:api-header] { "type": "basic", "title": "Form\\Form" } [/block] This class is the main class - it is your interface for everything in Form. Now of course, Form makes you interact with its subclasses which means you can not only use its methods but the methods of each class used by Form. [block:api-header] { "type": "basic", "title": "Options" } [/block] This is a set of options that can be set to modify Form's behavior. [block:code] { "codes": [ { "code": "Form::setOption('translate_from', [string]) ('validation.attributes')", "language": "php" } ] } [/block] By default Form tries to translate most labels, legends and help texts. For that it first tries to translate the string passed as is, and then it tries to look in a special place that can be defined with this variable - defaulting to 'validation.attributes.mykey'. [block:code] { "codes": [ { "code": "Form::setOption('required_class', [string]) ('required')", "language": "php" } ] } [/block] A class to add to fields that are set as required. [block:code] { "codes": [ { "code": "Form::setOption('default_form_type', [horizontal|vertical|inline|search]) ('horizontal')", "language": "php" } ] } [/block] By default when you call ***Form::open*** a fallback form type gets assigned to the form – this is the option that says which one is that type. It can be any of those values, or null if you want don't want to use Bootstrap's form classes. [block:code] { "codes": [ { "code": "Form::setOption('fetch_errors', [boolean]) (true)", "language": "php" } ] } [/block] Whenever you call the ***open*** method, if this option is set to true, Form will look into the Session array for a ***Message*** objects that would have been created by the -***>with_errors()*** method of ***Redirect***. Which means that if on failed validation you do ***Redirect::to()->with_errors()***, Form will automatically fetch said errors and display them on the corresponding fields without having to type anything. [block:code] { "codes": [ { "code": "Form::setOption('automatic_label', [boolean]) (true)", "language": "php" } ] } [/block] Allows the user to turn on or off the automatic labeling feature. When it's on, if you give per example ***foo*** as a field name and no label, Form will assume ***foo*** is also to be used as label. Form will then attempt to translate it, capitalize it, and use it as label. With this option turned off, if no label is specific, no label tag will be printed out. [block:code] { "codes": [ { "code": "Form::setOption('live_validation', [boolean]) (true)", "language": "php" } ] } [/block] Whether Form should try to apply Laravel's Validator rules as live validation attributes. [block:code] { "codes": [ { "code": "Form::setOption('push_checkboxes', [boolean]) (true)", "language": "php" } ] } [/block] Whether checkboxes should always be present in the POST data, no matter if you checked them or not [block:code] { "codes": [ { "code": "Form::setOption('TwitterBootstrap3.labelWidths', array('large' => 2, 'small' => 3)) ?>", "language": "php" } ] } [/block] Set the Bootstrap label width for your form. [block:api-header] { "type": "basic", "title": "Helpers" } [/block] [block:code] { "codes": [ { "code": "Form::populate([array|Eloquent])", "language": "php" } ] } [/block] Populates the fields with an array of values or an Eloquent object. [block:code] { "codes": [ { "code": "Form::withErrors([Validator])", "language": "php" } ] } [/block] If you have an ***$errors*** variable from a failed validation, the Form will automatically fetch it from Session and set the corresponding fields as incorrect and display the error message right next to them. This is if you're calling ***withErrors*** in your view. If you're in the controller, you can simply pass the ***$validator*** object to Form and it will work just the same. [block:code] { "codes": [ { "code": "Form::withRules([array])", "language": "php" } ] } [/block] Let you pass an array of Laravel rules to Form, to let it try and apply those rules live with HTML attributes such as ***pattern***, ***maxlength***, etc. [block:code] { "codes": [ { "code": "Form::framework([TwitterBootstrap3|ZurbFoundation5|null])", "language": "php" } ] } [/block] Select which CSS framework Form should use for its syntax – each gives you more or less access to the available methods. Per example you can't use Bootstrap's ***->blockHelp*** method while using Zurb, etc. [block:code] { "codes": [ { "code": "$error = Form::getErrors([string])", "language": "php" } ] } [/block] This is equivalent to [block:code] { "codes": [ { "code": "$error = isset($errors) ? $errors->first('field') : null.", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "Form builders" } [/block] [block:code] { "codes": [ { "code": "Form::legend([string])", "language": "php" } ] } [/block] This opens a Bootstrap ***legend>*** tag in your form – the string passed to Form can be a translation index since Form will attempt to translate it. [block:code] { "codes": [ { "code": "Form::open()", "language": "php" } ] } [/block] The ***open*** method mirrors Laravel's, which means you can refer to the doc for it on Laravel's website. But it also support the magic methods introduced by Bootstrapper for backward compatibility : [block:code] { "codes": [ { "code": "Form::horizontal_open()\nForm::secure_open()\nForm::open_for_files()\nForm::secure_vertical_open_for_files()", "language": "php" } ] } [/block] You can mix it up however you want as long as each block remain intact [block:code] { "codes": [ { "code": "Form::close()", "language": "php" } ] } [/block] This is pretty straightforward, simply prints out a </form> tag. It contains no argument or anything. [block:code] { "codes": [ { "code": "Form::actions([string, ...])", "language": "php" } ] } [/block] Creates a ***<div class='form-actions'>*** tag to wrap your submit/reset/back/etc buttons. To output multiple buttons simply use multiple arguments [block:code] { "codes": [ { "code": "// Button class from Bootstrapper\nForm::actions( Button::submit('Submit'), Button::reset('Reset') )", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "Field Builders" } [/block] This is the one class you'll be using the two thirds of the time [block:code] { "codes": [ { "code": "Form::[classes]_[field]", "language": "php" } ] } [/block] This method analyze whatever unknown method you're trying to call and creates a field with it. It decomposes it as [classes]_[field] or [field]. As classes you can call all Bootstrap classes working on fields : **span1** to **span12** and **mini** to **xxlarge** [block:api-header] { "type": "basic", "title": "Form\\Field" } [/block] This class is what you actually get when you create a field, which means the method listed underneath are only accessible as chained methods after a field was created. [block:code] { "codes": [ { "code": "// Here you're using Form\nForm::populate($project)\n\n// Here you're actually using the Field class wrapped in Form\nForm::text('foo')", "language": "php" } ] } [/block] A Form class stops being a field the second that field is printed out. [block:code] { "codes": [ { "code": "$textField = Form::text('foo');\n$textField->class('myclass')", "language": "php" } ] } [/block] But can't do this [block:code] { "codes": [ { "code": "echo Form::text('foo')\nForm::class('myclass')", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "Interactions with the attributes" } [/block] [block:code] { "codes": [ { "code": "Form::text('foo')->addClass([string])", "language": "php" } ] } [/block] Adds a class to the current field without overwriting any existing one. This does differs front ***->class()*** will — just like any attribute setter — overwrite any existing value [block:code] { "codes": [ { "code": "Form::text('foo')->forceValue([string])", "language": "php" } ] } [/block] This forces the field value to a particular value, ignoring both POST data and ***Form::populate()*** values. [block:code] { "codes": [ { "code": "Form::text('foo')->value([string])", "language": "php" } ] } [/block] This sets a default value for a field — a text present in it but that will get overwritten by calls to ***Form::populate*** or POST data. [block:code] { "codes": [ { "code": "Form::text('foo')->[attribute]([value])", "language": "php" } ] } [/block] This sets the value of any attribute. Attributes containing dashes have to be replaced with an underscore, so that you'd call ***data_foo('bar')*** to set ***data-foo="bar"***. [block:code] { "codes": [ { "code": "Form::text('text')->setAttribute([string], [string])", "language": "php" } ] } [/block] This can be used as a fallback to the magic methods, if you really want to set an attribute that contains an underscore. [block:code] { "codes": [ { "code": "Form::text('foo')->setAttributes([associative array])", "language": "php" } ] } [/block] This code allows you to mass-set a couple of attributes with an array. The following examples do the exact same thing. [block:code] { "codes": [ { "code": "Form::text('foo')->class('foo')->foo('bar')\n\nForm::text('foo')->setAttributes(array( 'class' => 'foo', 'foo' => 'bar' ))", "language": "php" } ] } [/block] The second method is not the cleanest per say but it is still useful if you have to set the same attributes for a group of fields. You can then just create an array with the attributes you want and assign it to each field in order to stay DRY. [block:code] { "codes": [ { "code": "Form::text('foo')->label([string])", "language": "php" } ] } [/block] This sets the label of a field to a string. If you're using Bootstrap this would have a specific meaning, since the label that will be created will automatically have the class control-label. [block:code] { "codes": [ { "code": "Form::text('foo')->addGroupClass('bar')", "language": "php" } ] } [/block] This adds specified class attributes to the parent control-group. [block:api-header] { "type": "basic", "title": "Helpers" } [/block] [block:code] { "codes": [ { "code": "$textField = Form::text('foo')->require()\n$textField = $textField->isRequired() // Returns \"true\"", "language": "php" } ] } [/block] This checks if a field has been set to required, be it by yourself or when transposing Laravel rules. [block:api-header] { "type": "basic", "title": "Form\\Checkable" } [/block] The Checkable is a subset of Field. This means all methods available with the Field are available with Checkable. The latter just offers a few more methods related to radios and checkboxes. [block:code] { "codes": [ { "code": "Form::radios('foo')->inline()\nForm::checkboxes('foo')->stacked()", "language": "php" } ] } [/block] This would set the current radios and checkboxes as inline, or stacked (vertical) [block:code] { "codes": [ { "code": "Form::checkbox('foo')->text('bar')", "language": "php" } ] } [/block] If you're printing only a single checkbox/radio, it's easier to use this method to set the text that will be appended to it. [block:code] { "codes": [ { "code": "Form::checkbox('foo')->check()\nForm::radio('foo')->check()\n\nForm::checkboxes('foo')->checkboxes('foo', 'bar')->check('foo_0')\n\nForm::radios('foo')->checkboxes('foo', 'bar')->check(0)", "language": "php" } ] } [/block] The check method allows you to check a one-off checkable element, or to check one in a group of checkable elements. For single elements you can just call check() without arguments – but when you're using a group you would need to specify which element is going to be checked. This is done differently if you're creating radios or checkboxes. This is because checkboxes can only be differentiated by their field name, while radio elements can only be differentiated by their value. The checkboxes you specify the name of the one you want to see checked, and for radios you specify its value. [block:api-header] { "type": "basic", "title": "Form\\ControlGroup" } [/block] Helpers and methods related to Bootstrap's control groups. If you set the ***$useBootstrap*** option to false earlier, this class is not accessible, nor are any of its methods. [block:code] { "codes": [ { "code": "Form::text('foo')->state([error|warning|info|success])", "language": "php" } ] } [/block] This set the state of a control group to a particular Bootstrap class. [block:code] { "codes": [ { "code": "Form::text('foo')->inlineHelp([string])\nForm::text('foo')->blockHelp([string])", "language": "php" } ] } [/block] This further adds an inline/block help text to the current field. Both can be called (meaning you can have both an inline and a block text) but can only be called once (which means if you call inlineHelp twice the latter will overwrite whatever you typed in the first one). [block:code] { "codes": [ { "code": "Form::text('foo')->append([string, ...])\nForm::text('foo')->prepend([string, ...])", "language": "php" } ] } [/block] Prepends one or more icons/text/buttons to the current field. Those functions use ***func_get_args()*** so you can per example [block:code] { "codes": [ { "code": "Form::text('foo')->prepend('@', '$')", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "Form\\Fields\\Input" } [/block] All classes related to Input-type fields. [block:code] { "codes": [ { "code": "Form::text('foo')->useDatalist([array])\n\nForm::text('foo')->useDatalist([Query], [string], [string (id)])", "language": "php" } ] } [/block] Creates a ***<datalist>*** tag and links it to the field in order to create a select/text mix. [block:api-header] { "type": "basic", "title": "Form\\Fields\\Select" } [/block] All classes related to Select-type fields (select, multiselect, etc) [block:code] { "codes": [ { "code": "Form::select('foo')->options([array], [selected])", "language": "php" } ] } [/block] Populates a ***<select>*** field with an array of options, where key will be the option's value and value will be its text. It sounds retarted explained like that but it means the following : [block:code] { "codes": [ { "code": "Form::select('clients')->options(array(\n 1 => 'Max',\n 3 => 'Clémence',\n 12 => 'Jean Valjean'\n));\n\n<select name=\"foo\">\n <option value=\"1\">Max</option>\n <option value=\"3\">Clémence</option>\n <option value=\"12\">Jean Valjean</option>\n</select>", "language": "php" } ] } [/block] Which looks really natural : you select a client's name and get it's ID in return. The second parameters allows to preselect one option, per example if in the above example we'd done -***>options($clients, 3)*** then Clémence would have been selected. [block:code] { "codes": [ { "code": "Form::select('foo')->select(3)", "language": "php" } ] } [/block] Alias for ***->value()***, selects an option. [block:code] { "codes": [ { "code": "Form::select('foo')->fromQuery([array], [string], [string (id)])", "language": "php" } ] } [/block] Populates a ***<select>*** field with the results of a Fluent/Eloquent query. Second argument is the attribute used by Form for the options text, third argument is the attribute used by Form for the options value (defaults to the ***id*** attribute). Second argument defaults to the model's ***__toString()*** method, thirds defaults to the model's ***get_key()*** method. Alternative use ***fromQuery*** for ***Form::select*** [block:code] { "codes": [ { "code": "Form::select('foo')->fromQuery([array], [callable], [array])", "language": "php" } ] } [/block] Sample: [block:code] { "codes": [ { "code": "Form::select('foo')->fromQuery(\n $collection,\n function($model) {\n return $model->id . $model->name;//option text\n },\n [//array option attributes\n 'value' => 'id',\n 'data-test' => function($model) {\n return $model->test_field;\n }\n ]\n);", "language": "php" } ] } [/block] Possible mixed use. [block:code] { "codes": [ { "code": "Form::select('foo')->placeholder('Select one option...')", "language": "text" } ] } [/block] Create a ghost option set as disabled by default to serve as placeholder for the select.