Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The "short name" validator loading you are attempting to use in your example only works if you register that short name / alias with the validator plugin manager (<code>Zend\Validator\ValidatorPluginManager</code>) first.</p> <p>One alternative to this (and the way I do it) is to inject instances of necessary custom validators when creating the form filter object. This is the way ZfcUser does it: </p> <pre><code>// Service factory definition from Module::getServiceConfig 'zfcuser_register_form' =&gt; function ($sm) { $options = $sm-&gt;get('zfcuser_module_options'); $form = new Form\Register(null, $options); $form-&gt;setInputFilter(new Form\RegisterFilter( new Validator\NoRecordExists(array( 'mapper' =&gt; $sm-&gt;get('zfcuser_user_mapper'), 'key' =&gt; 'email' )), new Validator\NoRecordExists(array( 'mapper' =&gt; $sm-&gt;get('zfcuser_user_mapper'), 'key' =&gt; 'username' )), $options )); return $form; }, </code></pre> <p>Source: <a href="https://github.com/ZF-Commons/ZfcUser/blob/master/Module.php#L100" rel="nofollow">https://github.com/ZF-Commons/ZfcUser/blob/master/Module.php#L100</a></p> <p>Here, the two <code>ZfcUser\Validator\NoRecordExists</code> validator instances (one for email and one for username) are injected into the constructor of the input filter object for the registration form (<code>ZfcUser\Form\RegisterFilter</code>). </p> <p>Then, inside the <code>ZfcUser\Form\RegisterFilter</code> class, the validators are added to the element definitions:</p> <pre><code>$this-&gt;add(array( 'name' =&gt; 'email', 'required' =&gt; true, 'validators' =&gt; array( array( 'name' =&gt; 'EmailAddress' ), // Constructor argument containing instance of the validator $emailValidator ), )); </code></pre> <p>Source: <a href="https://github.com/ZF-Commons/ZfcUser/blob/master/src/ZfcUser/Form/RegisterFilter.php#L37" rel="nofollow">https://github.com/ZF-Commons/ZfcUser/blob/master/src/ZfcUser/Form/RegisterFilter.php#L37</a></p> <p>I believe another alternative is to use the fully-qualified class name as the validator name (ie: "User\Validator\PasswordStrength" instead of just "PasswordStrengthValidator"), though i've never attempted this myself. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload