Download the PHP package hispanicode/validation without Composer

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

This class can be used to validate forms on the browser and server sides.

It can take an array of validation rules and generates JavaScript to perform validation on the browser side of given form fields.

The class can generate validation JavaScript code using jQuery that is performed for different form events like when the form input is changed, the form loses focus, when a key is released, etc..

It can also perform validation of the submitted form input on the server side with the class PHP code. Currently in can perform validation types like: required value, minimum length, maximum length, required file, file minimum and maximum size, file MIME type, image maximum width and height, checked checkbox, valid date and time format, IP address, valid email address, valid URL, match regular expression, maximum and minimum length, value equal to another input, valid number, minumum and maximum number, etc..

Important: for client-side validation it is necessary to include jQuery and file validation.js

Install with composer

composer require hispanicode/validation

Online example

Simple usage

Require the class file

require "src/Validation.php";
/* 
if install with composer 
require "vendor/autoload.php";
*/

New instance

use Hispanic\Validation;
$validation = new Validation();

Rules

$rules = array(
  "name" => "required|name|min_length:3|max_length:50",
  "email" => "required|email|min_length:6|max_length:80",
  "password" => "required|between:6-30",
  "confirm_password" => "required|equalsTo:password",
  "terms" => "checked",
);

Optional. Custom messages. For example translate in other language (French)

$messages = array(
  "name.required" => "Le champ :attribute est obligatoire",
  /* ... */
);

The default messages in distinct languages is possible in the language.php file. The spanish and english translates are availables but you can translate in your language.

//The default translate is "en" in this case not is need use the translate method.
//Translate in spanish
$validation->translate("es");

In the client validation is possible handle javascript events

$events = array(
  "name" => "keyup|blur|change",
  /* ... */
);

Start the client validation

//The $messages and $events params are optionals
$validation->client($rules, $messages, $events);

Generate the client validation is easy

//The argument is the id of the form
echo $validation->getClientValidation("#form");

For get the client messages set the next structure based in the bootstrap css styles

<form method="post" id="form">
    <div class="form-group">
        <label for="name">Name:</label>
        <input type="text" name="name" id="name" class="form-control" value="" />
        <p id="error_name"></p>
    </div>
    ...
</form>

For the server side is the server() method


use Hispanic\Validation;

$validation = new Validation();

//Is possible change the labels attributes with the attribute() method
$attributes = array(
  "name" => "Name",
  "confirm_password" => "Confirm Password",
  /* ... */
);

$validation->attributes($attributes);

$rules = array(
  "name" => "required|regex:/^[a-z]+$/|min_length:3|max_length:50",
  /* ... */
);

/* if you like the client validation is easy */
$validation->client($rules);

/* request */
if (isset($_POST["name"])) {
  $validation->server($rules); //The second argument is optional for the custom messages array

  //If is valid
  if ($validation->isValid()) {
      /* ok */
  } else {
    /* error */
    //get associative array with all errors
    $errors = $validation->getErrors();
    //get only one error, the first error.
    $first_error = $validation->getFirstError();
  }
}

Validation rules options


All versions of validation 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 hispanicode/validation contains the following files

Loading the files please wait ....