linelab-studio/zf2-validator-api-client

1.1.1 2020-01-13 16:41 UTC

This package is auto-updated.

Last update: 2024-04-14 03:01:43 UTC


README

Validator Email and Phone - Zend Framework 2.

Requirements

PHP 5.5 and later

Installation & Usage

Composer

To install the bindings via Composer, add the following to composer.json:

{
  "require": {
    "linelab-studio/zf2-validator-api-client": "1.0.1"
  }
}

Then run composer install

Usage

Add configuration data. The configuration can be in the module configuration or in the project autoload files.

'LabValidator' => [
    'apiKey' => 'exampleApiKey',
    'host' => 'https://localhost/validator/api'
],

Creation of the ZF2 Validator class.

Two validators are available:

  • EmailValidator (namespace LabValidator\EmailValidator)
  • PhoneValidator (namespace LabValidator\PhoneValidator)
<?php
namespace App\Validator;

class EmailAddressValidator extends LabValidator\EmailValidator
{
    public function __construct(array $config = null)
    {
        parent::__construct($config);
    }
}
?>

Adding a validator to the field in the form

public function validatorAction()
{
    $form = new Form();
    $form
       ->add([
            'name' => 'email',
            'type' => 'email',
            'attributes' => [
                'required' => true,
            ],
            'options' => [
                'label' => 'Email',
                'validators' => [
                    $this->serviceLocator->get(EmailAddressValidator::class)
                ]
            ]
        ]);
}

Author

studio@linelab.pl