Laravel-Bootstrap-Modal-Form
A form validation extension for your Laravel app. Use when embedding a Bootstrap form into a Bootstrap/jQuery modal. This script keeps modal open, submits form via AJAX, queries your Laravel validation rules, and populates error messages.
Requirements
Quick Installation
Via Bower:
bower install jerseymilker/laravel-bootstrap-modal-form --save
Basic Usage
- Embed Bootstrap form into Bootstrap/jQuery modal.
- Setup Laravel validation.
- Include this script.
- Add
class="bootstrap-modal-form"
to form. - Add
class="bootstrap-modal-form-open"
to modal open button.
Additional Notes
- Script does not handle CSRF tokens. Use Laravel's _token field in your forms if needed.
- Script submits via
POST
form action. Use Laravel's method spoofing if you need to submit viaPUT
,PATCH
, orDELETE
. - If script detects file input, FormData object will be used (requires IE10+, more info on browser compatibility here).
Shameless Plug
I highly recommend BootForms form builder package by Adam Wathan. This is a great helper which makes generating Bootstrap form markup super easy. It even auto-detects Laravel's validation state and outputs error messages for most field types.
Example:
{!! BootForm::text('First Name', 'first_name') !!}
Generates:
<div class="form-group {!! $errors->has('first_name') ? 'has-error' : '' !!}">
<label for="first_name">First Name</label>
<input type="text" class="form-control" id="first_name">
{!! $errors->first('first_name', '<p class="help-block">:message</p>') !!}
</div>