Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fizz is a connector between Laravel 3's Form and Validator classes, providing 2 core pieces of functionality: form field value population, and error highlighting
PHP
Branch: error_check_up…
Pull request Compare This branch is 10 commits behind master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
config
library
README.md
bundle.php
start.php

README.md

FIZZ

Fizz is a connector between Laravel's Form and Validator classes, providing 2 core pieces of functionality: form field value population, and error highlighting. Its goals are to bridge the gap between these two related libraries, and yet stay flexible enough to stay out of the developer's way when needed.

Installation

Install Fizz using artisan:

php artisan bundle:install fizz

, then in application/bundles.php, add the following:

return array(
    'fizz' => array('auto' => true)
);

This will load the Fizz library upon every request.

Usage

Fizz currently wraps around Laravel's form library and adds some functionality. Form field population gets handled automagically, you don't need to worry about that. However, in the current implementation of Form, there is a disconnect between it and Validator. Some would see this as a bad thing, I actually think it's a strength. Nothing worse than a framework that tries to do everything for you.

To get error handling working, whenever you add some validation to your code, do the following:

$post = Input::all();

$rules = array(
    'email' => 'required|email',
    'password' => 'required'
);

$validation = Validator::make($post, $rules);
Fizz\Form::set_validator($validation);

What this does is make the $validator object available to Fizz, and allows us to do some error checking. If any errors are found for a given form element, it will attach a "form-error" class to that field. This is the default class however, and can be changed by setting your own configuration setting in any of your config files, like so:

'fizz_error_class_name' => 'form-error'

It is recommended that you replace the Laravel Form library calls, so that this bundle is truly plug 'n' play, by replacing the following in your application/config/application.php file:

'Form' => 'Laravel\\Form',

With:

'Form' => 'Fizz\\Form',

What this does, is basically make all Form requests in your markup, directed to Fizz\Form. (Otherwise you need to call Fizz\Form::.etc. everywhere in your HTML!)

One thing to note is that this does NOT remove the original Laravel Form calls. In fact, all it's doing is wrapping your call with some functionality to check for errors, field values.etc, then sending the call along to the Laravel\Form library.

Gotchas

Fizz highlights confirmation fields by default if there is an error with the associated field. The reason for this is because there is currently no way to determine what kind of validation rule has been broken for a given field. I am looking into updating how validation errors are added for Fizz so that this can be done more accurately (Ie. only highlight confirmation fields if it's a confirmation error).

Easy!

Something went wrong with that request. Please try again.