Download the PHP package werx/validation without Composer

On this page you can find all versions of the php package werx/validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package validation

Validation Library

Simple input validation.

Build Status Total Downloads Latest Stable Version

Usage

There are two components to this library. A set of validation methods and an input validation engine.

Validators

The Validator class can be used to quickly validate a single piece of input.

The following validators are available. Each validator returns a bool. true = passed validation, false = failed validation.

Validation Engine

The Validation Engine is used to validate a set of data against a set of rules.

Usage

First, get an instance of the Validation Engine:

Then add rules:

Parameters

Now you can get a validation result.

Validating Input Arrays

Sometimes you aren't using a simple string as your input field name. Let's say your HTML input form is something like this:

To build a rule for in this scenario, separate the array name and key name with a period when adding your rule.

Closures

In addition to predefined validation methods from the Validator class, you can also use closures to create custom validation methods.

Three values will be passed to your closure:

  1. The full data set being validated.
  2. The id of the element being validated.
  3. The label for the element being validated.

The closure is expected to return an array.

Rulesets

What if you want to save groups of rules instead of adding each rule individually every time you want to validate them? We've got you covered.

Create a new class that extends werx\Validation\Ruleset and add your rules in the constructor.

Then when you are ready to validate this group of rules:

Utility Methods

There are a couple utilities to make dealing with validation results easier.

getErrorSummary()

Returns a simple array containing a list of validation error messages.

getErrorSummaryFormatted()

Returns the error summary formatted as an html unordered list (<ul>).

getErrorFields()

Returns list of fields that had an error. Useful if you want to apply some decoration to your form indicating which fields had a validation errors.

getRequiredFields()

Once you've added your rules, you can get back a list of required fields. This is useful when you want to indicate on your form which fields must be completed.

addCustomMessage()

Allows you to set custom error messages.

When displaying the error messages, {name} will be replaced with the name of the field being validated. The rest of the field is parsed with sprintf() so that parameters like minlength can be placed in the returned error message.

Examples:

Installation

This package is installable and autoloadable via Composer as werx/validation. If you aren't familiar with the Composer Dependency Manager for PHP, you should read this first.

Contributing

Unit Testing

Coding Standards

This library uses PHP_CodeSniffer to ensure coding standards are followed.

I have adopted the PHP FIG PSR-2 Coding Standard EXCEPT for the tabs vs spaces for indentation rule. PSR-2 says 4 spaces. I use tabs. No discussion.

To support indenting with tabs, I've defined a custom PSR-2 ruleset that extends the standard PSR-2 ruleset used by PHP_CodeSniffer. You can find this ruleset in the root of this project at PSR2Tabs.xml

Executing the codesniffer command from the root of this project to run the sniffer using these custom rules.


All versions of validation with dependencies

PHP Build Version
Package Version
Requires php Version >= 5.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package werx/validation contains the following files

Loading the files please wait ....