Download the PHP package jridgewell/form-validator without Composer

On this page you can find all versions of the php package jridgewell/form-validator. 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 form-validator

FormValidator Build Status

FormValidator allows you to create and validate forms using a simple rule based approach. It uses an API very similar to Rails' ActiveRecord.

Basics

A form file is just a class that extends the \FormValidator\Form class In this example, the form validator checks if name isn't empty

test.form.php (the model)

index.php (the controller)

form.html.php (the view)

About the View

  1. If the form fails validation, by using the $form->input method, we preserve whatever value the user typed into that field (except for password fields)
  2. The form must have a field with the name attribute set to the name of the form class (name="TestForm" in our example). Using the $form->submit method takes care of this requirement.

Installation

Via Composer

composer require "jridgewell/form-validator:1.*"

Then just add require 'vendor/autoload.php'; to any code that requires FormValidator.

The Validations Array

The $validations array contains all the form fields and rules that need to pass, for the form to be valid. In the example above, it showed a single rule applying to one form element, but you can apply multiple rules to an element by using an array.

In our html file, if we wanted to show the errors for the validations, we could do the following:

Validation Array Options

Most validations also support passing in an options array. This allows for custom messages, and can allow for a field to be optional (blank). Please see the validation for acceptable parameters.

List of validations

Simple Validations

Validation Options Description

Validation::anything()

No options

This field is always valid

Validation::acceptance()

message => 'message'
Use a custom error message
accept => 'truthy'
The value that this field will be compared (==) with. Defaults to true

This field must be accepted (truthy)

Validation::email()

message => 'message'
Use a custom error message
optional => true
Will accept a blank field. If this field is not blank, will preform the validations.

This field must be a valid email

Validation::length()

message => 'message'
Use a custom error message
optional => true
Will accept a blank field. If this field is not blank, will preform the validations.
is => $x
The length of this field must be equal to $x
minimum => $x
The length of this field must be at least (<=) $x
maximum => $x
The length of this field must be at most (>=) $x

This field's number of characters must be in the supplied range. If no options are passed, this field will always be valid

Validation::numericality()

message => 'message'
Use a custom error message
optional => true
Will accept a blank field. If this field is not blank, will preform the validations.
only_integer => true
Only whole integers are acceptable. If not supplied, whole integers or floats are acceptable.
even => true
Only even numbers are acceptable
odd => true
Only odd numbers are acceptable
equal_to => $x
The number must be equal to $x
less_than => $x
The number must be less than $x
less_than_or_equal_to => $x
The number must be less than or equal to $x
greater_than => $x
The number must be greater than $x
greater_than_or_equal_to => $x
The number must be greater than or equal to $x

This field must be a number

Validation::presence()

message => 'message'
Use a custom error message

This field must not be empty

Validation::url()

message => 'message'
Use a custom error message
optional => true
Will accept a blank field. If this field is not blank, will preform the validations.

This field must be a valid url

Advanced Validations (require parameters)

Validation Parameter Options Description

Validation::confirmation($func)

$func
A (callable) callback to match against. It's return value will be type and value checked (===) against this field
message => 'message'
Use a custom error message
optional => true
Will accept a blank field. If this field is not blank, will preform the validations.

This field must match the return value of $other_field_func. Useful for confirming a password in a second field.

Validation::exclusion($array)

$array
A list of unacceptable values.
message => 'message'
Use a custom error message
optional => true
Will accept a blank field. If this field is not blank, will preform the validations.

This field must not be equal (==) to a value inside $array.

Validation::format($regex)

$regex
The regex to match this field against
message => 'message'
Use a custom error message
optional => true
Will accept a blank field. If this field is not blank, will preform the validations.

This field must match against the supplied $regex

Validation::inclusion($array)

$array
A list of acceptable values.
message => 'message'
Use a custom error message
optional => true
Will accept a blank field. If this field is not blank, will preform the validations.

This field must be equal (==) to a value inside $array.

Validation::validateWith($func)

/td>
$func
A custom (callable) callback to match against.
message => 'message'
Use a custom error message
optional => true
Will accept a blank field. If this field is not blank, will preform the validations.

This validation allows for a custom function to preform the field validation. It's return value must be (===) true, or else it will use the return value as the field's error message

Advanced Validation Examples

Validation::confirmation($other_field_func)

Validation::exclusion($array)

Validation::format($regex)

Validation::inclusion($array)

Validation::validateWith($func)

This validation requires a (callable) callback. This callback is then provided with the submitted field data as it's only parameter. The callback can either return true and the validation will pass, or return anything else and the return will be used as the error message for the field.


All versions of form-validator with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
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 jridgewell/form-validator contains the following files

Loading the files please wait ....