Note that there are some explanatory texts on larger screens.

plurals
  1. POzf2 Form class issue
    text
    copied!<p>ABOVE URLS IS NOT ANSWERS, I AM ALREADY PASSING DB ADAPTOR</p> <p>I am having issue in calling "Db\RecordExists" in Filter form class.</p> <p>I AM ALREADY PASSNING DB ADAPTPR IN CONTROLLER.</p> <pre><code>$sm = $this-&gt;getServiceLocator(); $dbAdapter = $sm-&gt;get('Zend\Db\Adapter\Adapter'); $form-&gt;setInputFilter(new RegisterStepFirstFilter($dbAdapter)); $form-&gt;setData($request-&gt;getPost()); if (!$form-&gt;isValid()) { } </code></pre> <p>I want to check email exist or not during registration. I am using Zend framework form class for Registration. I have define the form class and Class Filter and calling them in Controller.</p> <p>Every things is working fine except "Db\RecordExists". The form is not checking unique email against db ad it simply submitter. However the other filters and validators are working properly </p> <pre><code>$this-&gt;add(array( 'name' =&gt; 'user_email', 'required' =&gt; true, 'filters' =&gt; array( array('name' =&gt; 'StripTags'), array('name' =&gt; 'StringTrim'), array('name' =&gt; 'HtmlEntities'), ), 'validators' =&gt; array( array('name' =&gt; 'EmailAddress'), array('name' =&gt; 'StringLength', 'options' =&gt; array('encoding' =&gt; 'UTF-8', 'min' =&gt; 1, 'max' =&gt; 200,), array('name' =&gt; 'Db\RecordExists', 'options' =&gt; array('table' =&gt; 'y2m_user','field' =&gt; 'user_email', 'adapter' =&gt; $dbAdapter),), ), ), )); </code></pre> <p>my form class is </p> <pre><code>&lt;?php namespace User\Form; use Zend\Form\Form; class RegisterStepFirst extends Form { protected $captchaElement= null; public function __construct($name = null) { // we want to ignore the name passed parent::__construct('user'); $this-&gt;setAttribute('method', 'post'); //$this-&gt;add(array('hash','csrf_token',array('salt'=&gt;get_class($this).'s3cr3t%Ek@on9!')); $this-&gt;add(array( 'type' =&gt; 'Zend\Form\Element\Csrf', 'name' =&gt; 'csrf', 'options' =&gt; array( 'csrf_options' =&gt; array( 'timeout' =&gt; 600, 'salt' =&gt; 'unique' ) ) )); $this-&gt;add(array( 'name' =&gt; 'user_given_name', 'type' =&gt; 'Text', 'options' =&gt; array( 'label' =&gt; 'Display Name', ), 'attributes' =&gt; array( 'id' =&gt; 'user_given_name', ) )); $this-&gt;add(array( 'name' =&gt; 'user_email', 'type' =&gt; 'Text', 'options' =&gt; array( 'label' =&gt; 'Email', ), 'attributes' =&gt; array( 'placeholder' =&gt; 'mail@yourdomain', //set selecarray()ted to '1' 'id' =&gt; 'user_email', 'size' =&gt; '100', ) )); $this-&gt;add(array( 'name' =&gt; 'user_password', 'type' =&gt; 'Password', 'options' =&gt; array( 'label' =&gt; 'Password', ), 'attributes' =&gt; array( 'id' =&gt; 'user_password', 'size' =&gt; '100', ) )); $this-&gt;add(array( 'name' =&gt; 'user_retype_password', 'type' =&gt; 'Password', 'options' =&gt; array( 'label' =&gt; 'Confirm Password', ), 'attributes' =&gt; array( 'id' =&gt; 'user_retype_password', 'size' =&gt; '100', ) )); $this-&gt;add(array( 'name' =&gt; 'submit', 'type' =&gt; 'Submit', 'attributes' =&gt; array( 'value' =&gt; 'Register', 'id' =&gt; 'submitbutton', ), )); } } </code></pre> <p>And the Filter is </p> <pre><code>&lt;?php namespace User\Form; use Zend\InputFilter\InputFilter; class RegisterStepFirstFilter extends InputFilter { private $dbAdapter; public function __construct($dbAdapter) { $this-&gt;add(array( 'name' =&gt; 'user_given_name', 'required' =&gt; true, 'filters' =&gt; array( array('name' =&gt; 'StripTags'), array('name' =&gt; 'StringTrim'), array('name' =&gt; 'HtmlEntities'), ), 'validators' =&gt; array( array('name' =&gt; 'Alpha','options' =&gt; array('allowWhiteSpace' =&gt; true,),), array('name' =&gt; 'StringLength','options' =&gt; array('encoding' =&gt; 'UTF-8', 'min' =&gt; 1,'max' =&gt; 100,),), ), )); $this-&gt;add(array( 'name' =&gt; 'user_email', 'required' =&gt; true, 'filters' =&gt; array( array('name' =&gt; 'StripTags'), array('name' =&gt; 'StringTrim'), array('name' =&gt; 'HtmlEntities'), ), 'validators' =&gt; array( array('name' =&gt; 'EmailAddress'), array('name' =&gt; 'StringLength', 'options' =&gt; array('encoding' =&gt; 'UTF-8', 'min' =&gt; 1, 'max' =&gt; 200,), array('name' =&gt; 'Db\RecordExists', 'options' =&gt; array('table' =&gt; 'y2m_user','field' =&gt; 'user_email', 'adapter' =&gt; $dbAdapter),), ), ), )); $this-&gt;add(array( 'name' =&gt; 'user_password', 'required' =&gt; true, 'filters' =&gt; array( array('name' =&gt; 'StripTags'), array('name' =&gt; 'StringTrim'), array('name' =&gt; 'HtmlEntities'), ), 'validators' =&gt; array( array('name' =&gt; 'StringLength','options' =&gt; array('encoding' =&gt; 'UTF-8', 'min' =&gt; 3,'max' =&gt; 60,), ), ), )); $this-&gt;add(array( 'name' =&gt; 'user_retype_password', 'required' =&gt; true, 'filters' =&gt; array( array('name' =&gt; 'StripTags'), array('name' =&gt; 'StringTrim'), array('name' =&gt; 'HtmlEntities'), ), 'validators' =&gt; array( array('name' =&gt; 'StringLength','options' =&gt; array('encoding' =&gt; 'UTF-8', 'min' =&gt; 3,'max' =&gt; 60,),), array('name' =&gt; 'identical','options' =&gt; array('token' =&gt; 'user_password'),) ), )); } } </code></pre>
 

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