Download the PHP package sheadawson/silverstripe-zenvalidator without Composer

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

SilverStripe ZenValidator

Build Status

Description

ZenValidator aims to make silverstripe form validation as painless as possible, by allowing configuration of serverside and clientside validation through one simple API. Parsley.js is used for the clientside validation in the frontend.

Installation

composer require sheadawson/silverstripe-zenvalidator

SilverStripe 4 support

This version of the module only supports SilverStripe 4. The current version of the module try as much as possible to remain compatible with previous code. SilverStripe 4 support is pretty much work in progress so you can expect a few issues.

You can also check this other module that uses ParsleyJS as well: https://github.com/praxisnetau/silverware-validator

Future versions of this module will break BC to promote namespaced classes and other improvements.

SilverStripe 3 support

For SilverStripe 3 support, please use branch 1.

Using with modern jQuery

Due to entwine, modern jquery is not supported because of an issue in entwine.js. This module provides an updated version of entwine that drop support for old version of IE (<9).

This module expects that you include your own version of jQuery. However, as a convenience we have included a ZenValidator::globalRequirements helper. This helper also includes the updated version of entwine.

Also, we try to avoid using entwine entirely if possible. You can use the legacy behaviour with

Validation Constraints

Out of the box constraints include:

Usage examples

Create a form, add ZenValidator.

The following examples demonstrate various ways to add constraints to the above form example.

Required fields

The addRequiredFields() is available for quick and clean adding of required fields.

Required Fields - Basic
Required Fields - Custom Messages

Other Constraints

All other constraints are added via the setConstraint() method. This method takes 2 parameters: $fieldName and $constraint. See examples below.

Value Constraints

Test for number of min, max or between range value

Min

Max

Range

Length Constraints

Test for a min, max or between range length of string

Min

Max

Range

Check Constraints

Test for a min, max or range of elements checked

Min

Max

Range

Type Constraints

The Constraint_type constraint can be used to validate inputs of type email, url, number, integer, digits or alphanum. Pass one of said options as the first parameter into the constructor.

Email

URL

Number

Integer

Digits

Alphanum

Equal To Constraint

Validates that the value is identical to another field's value (useful for password confirmation check).

Not Equal To Constraint

Validates that the value is different from another field's value (useful to avoid duplicates).

Regex validation

Check for a valid hex color, for example…

Remote validation

Validate based on the response from a remote url. Validation is based on the response http status code. A status of 200 will validate, anything else will cause a validation error.

The above example will send an ajax request to my checkusername method on the same controller as the Form. A request var with a key the same as the field name will contain the value to test. So my checkusername method might look something like this:

All arguments/settings for the Constraint_remote constructor:

By default, ZenValidator uses a custom async validator that reads error message in your 4xx responses and display them below the invalid field (instead of a generic message "this value seems invalid").

For serverside validation: if a relative url is given the response will be obtained internally using Director::test, otherwise curl will be used to get the response from the remote url.

Setting Custom Messages

Any of the above examples can be configured to display a custom error message. For example:

Bulk setting of constraints

The setConstraint() method is also chainable so you can:

Removing constaints

OR

Customising frontend validation behaviour (Parsley)

It is likely that you may want to have your validation messages displaying in a custom element, with custom classes or any other custom frontend validation behaviour that is configurable with Parsley. In this case, you can set the third parameter ($defaultJS) of Zenvalidator's constructor to false.

Or set globally via yml

This will tell ZenValidator not to initialise with the default settings, and also to add the class "custom-parsley" to the form. You'll then need to add some custom javascript to the page with your own settings, for example:

Warning: $(elem).parsley() can return an array (in which can, attaching subscribe will fail) in case you match multiple forms. Use the following syntax instead if you need to match multiple elements:

See Parsley.js for the full list of configuration settings

CMS Usage

To use ZenValidator in the CMS, simply implement a getCMSValidator() method on your custom Page type or DataObject class

Image Dimension Constraints (CMS only)

You can add constraints to image selection/upload fields to ensure that users are saving images of the correct size or shape, or that the image is of a minimum/maximum width and height to prevent issues with the display of the image in the site.

Note: the validation is run when the page is saved, not at time of image choosing or upload.

Width

Use this to require the width of an image to be a certain number of pixels. Handy if you require images to be an exact size.

Height

Use this to require the height of an image is the specified pixels.

Width and Height

Use this to require both the width and height are the specified pixels.

Ratio

Use this to require images to be a certain shape, for example 6:4 photo, 5:5 square etc. Handy when you need an image to be a particular shape but are relaxed about the size as that might be dealt with by CSS.

Min width

Use this to ensure the width of an image is equal to or greater than the specified pixels, handy to ensure that users don't use images which are too small and might loose quality if stretched by CSS.

Min height

Use this to ensure that the height of an image is equal to or greater than the specified pixels.

Min width and height

Use this to ensure that the width and the height of the image are equal to or greater than the specified pixels.

Max width

Use this to ensure that the width of an image is less than or equal to the specified pixels. Handy to ensure that users don't select images far larger than required, especially if these images have a max-width set by CSS as that would result in a lot of wasted bandwidth.

Max height

Use this to ensure the height of an image is less than or equal to the specified pixels.

Max width and height

Use this to ensure the width and height is of an image does not exceed the specified pixels.

Validation Logic - Conditional Constraints

This feature allows you to specify under what conditions a field should or should not have it's validation constraints applied, based on the value(s) of other fields on the form. The concept borrows heavily from and compliments Uncle Cheese's Display Logic module. Note that no frontend logic is applied, this is backend only. If you use display logic, that will allow you to hide fields that shouldn't be shown/validated on the frontend.

Validation Logic Examples

You can use the following conditional:

Extra validators

You can also use extra validators crafted by the community. The module is shipped with the default validators:

Javascript and language files are loaded only if you use these validators.

No validation

In some scenarios, you don't want to trigger validation when submitting the form (i.e.: "previous" button in a multi step form). Although this is easy to achieve by yourself, the module provides a standard implementation for doing this.

Instead of using the standard FormAction class, you can use its subclass "FormActionNoValidation". It will prevent the client and server side validation from happening.

Extending

You can create your own validation constraints by subclassing the abstract ZenValidatorConstraint class. For frontend implementation of your custom validator, see Parsley.extend.js. Unfortunately there is no real documentation other than the code itself at this stage so good luck!

For everything else in the frontend (triggers, error classes, error placement, etc) See the Parsley.js documentation

Maintainers

TODO


All versions of silverstripe-zenvalidator with dependencies

PHP Build Version
Package Version
Requires silverstripe/framework Version ^4 || ^5
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 sheadawson/silverstripe-zenvalidator contains the following files

Loading the files please wait ....