Home

Status

Veto is currently in rapid development and is not recommended for use in a production environment. Development has slowed recently and it is mostly stable - people just need to test it and report any errors :)

What is Veto?

Veto is a PHP and Javascript form validation library.

Why a validation library?

Validation code is boring!!

Every time I create a new form I have to write the usual code checking that a field has some content, then check that my select boxes haven't been tampered with, my currency fields don't have negative values, etc. etc. etc.

Veto is the end of this - with a easy to use syntax there is no reason to get stressed over validation. Just set your fields in a few lines at the top of your script (or in your controller if your really good), output the fields using veto helpers - and like magic the data is validated both on the server side and the client side.

It is my hope that Veto will make the lives of developers just a little bit easier, and hopefully encourage some of the many sites which use no validation to get some.

What makes Veto different

There are a number of javascript libraries dealing with validation, there are less PHP libraries - but still enough that on the surface it looks like there is no need for another.

The problem with these libraries is that they appear to have been written for a specific use case and without thought to the problems today's web developers face in regards to validating forms where the content changes dynamically through AJAX, etc.

Veto is build with this in mind and with one eye on the future to allow easy expansion of the library.

Syntax

In developing Veto the aim is to give the developer as many options as possible, while offering sensible defaults. The following code samples are identical in functionality:

	$first_name_field = new vtField('first_name');
		$first_name_field->add(new vtRequiredValidation());
	$form->add($first_name_field);
	$form->add(vtField('first_name')->required());

It is expected the second syntax will be used most often with the first being used for more complicated validations.

These will generate the error "First Name is required" if validation fails - this can be overwritten by passing an error message to the vtRequiredValidation() constructor or to required() eg:

	$form->add(vtField('first_name')->required("Why haven't you told me your first name?"));

Javascript

The javascript is being written to match the php as closely as possibly. As can be seen from the examples below.

	var first_name_field = new vtField('first_name');
		first_name_field.add(new vtRequiredValidation());
	form.add(first_name_field);
	form.add(vtField('first_name').required());
	form.add(vtField('first_name').required('Why haven\'t you told me your first name?'));

Which is, apart from the syntax difference in PHP and javascript, identical.

Write Once

If you don't need to modify the validations inline it is likely you won't need to use any javascript at all. Fields can be output using the form helpers provided by Veto and these will include the javascript validation code for you.

This way it is guaranteed that the data will be validation wether the user has javascript or not, and if they do they will have a better, more responsive experience.

	<?=$form->textField('first_name')?>

Server side technologies

Veto is currently only available for PHP, although it is possible that it will be ported in the future.

Features

Go to the features page

Configuration

Configuration Options

Todo

  • Add more common validations - including ajax helper for custom validations, Possibly phone number and post/zip code validation)
  • Ensure javascript works with IE
  • Optimize Javascript
  • Add conditional validations (if 1 field is empty, etc.)
  • Add "variables" to labels and rules - for example a validation could be options: A, B, C, or %v{your_value} where your_value is a field name - this would evaluate to A, B, C, or whatever is entered in the your_value field. %n could be used to get names. Without the {} it would default to the current field name/value.
  • Create proper documentation on the wiki, with example pages and tutorials - showing all the functionality of veto

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.