Skip to content

form

Opens a <form> with CSRF token, method spoofing and model binding. How fields get their values from the model: Forms.

Lte3::formOpen(array $attrs = []): string
Lte3::formClose(): string
{!! Lte3::formOpen(['action' => route('admin.posts.update', $post), 'method' => 'PUT', 'model' => $post]) !!}
...
{!! Lte3::formClose() !!}
AttrTypeDefaultDescription
actionstring'#'Form URL
methodstring'POST'GET renders method="GET"; any other method renders method="POST" plus a hidden _method with the given value
modelmixednullSource of field values until formClose()
filesbooltrue (config default)Adds enctype="multipart/form-data"
classstringCSS class of the form
stylestringInline style
disabledboolAdds disabled to the <form> tag. It does not disable the fields
dataarray['confirm' => 'Sure?'] → data-confirm="Sure?"
labelstringA <label> (HTML) in a form group right after the opening tag
closeboolPrints </form> right away — for a form without fields, e.g. a target of form="..." buttons
any of view.field_attrsPrinted as HTML attributes, e.g. id, title, autocomplete

For non-GET forms the hidden inputs _method, _token and the fields of Lte3::formHiddenUsing() are added. A GET form gets none of them.

formClose() prints </form> and unbinds the model, so fields after it no longer take values from it.

Create and update with one view:

{!! Lte3::formOpen([
'action' => $post->exists ? route('admin.posts.update', $post) : route('admin.posts.store'),
'method' => $post->exists ? 'PUT' : 'POST',
'model' => $post,
]) !!}

Upload form that submits itself when a file is picked (see Actions and AJAX):

{!! Lte3::formOpen(['action' => route('admin.import'), 'class' => 'js-form-submit-file-changed']) !!}
{!! Lte3::file('import') !!}
{!! Lte3::formClose() !!}

A form with an id, for buttons outside of it:

{!! Lte3::formOpen(['action' => route('admin.posts.bulk'), 'id' => 'bulk-form', 'close' => true]) !!}
<button type="submit" form="bulk-form" name="action" value="publish" class="btn btn-default">Publish</button>