Take the 2-minute tour ×

I wanted to bypass the annoying validation for the Select Element in Zend Framework 2. My requirement is that I have two select drop down boxes where I pass the values from the left select box to right select box and finally when I click the submit button, I post the values from right select box.

So basically the left select box is there to show the values to the user, my problem is that in the left select box as no value is selected it throws this error:

["selectAll"] => array(1) {
      ["isEmpty"] => string(36) "Value is required and can't be empty"

I have seen some old posts from Stackoverflow, where this is possible in Zend Framework 1 like one can disable the validation for the particular select element´





which some how these methods are not available in Zend Framework 2. In case if somebody has a solution of how disable the validation for a particular select element, please do share your knowledge, will be hepful for people getting into Zend Framework 2.


In my Form-

    $select = new Element\Select('selectAllElement');
    $select->setAttribute('title', 'Select a Value')
            ->setAttribute('id', 'id');

    $options = array(
           //Fetching the values from database

   $select->setAttribute('multiple', 'multiple')
        ->setAttribute('required', false)


As per request from Sam, I have provided the code how I am adding the select element to my form and setting the attributes.

NOTE: I am not using any FIELDSETS

share|improve this question
Please provide code for where you set up your forms validation. Usually adding 'required' => false within validation configuration should be enough if i'm not mistaken. –  Sam Oct 19 '12 at 11:40
@Sam provided the code as per your request, please do go through it and let me know how I can solve this problem. Thanks –  user1686230 Oct 19 '12 at 12:13
Still missing the validators. The setRequired() is only for the HTML-Attributed required="(bool)" not for the validation required. Please see framework.zend.com/manual/2.0/en/modules/… for further details on inputFilters regarding Zend\Form –  Sam Oct 19 '12 at 12:30
Hi Sam, thanks for pointing it out, I followed your tip and made 'required' => false in my inputFilter and now it is working. I have upvoted you since you gave your answers only in comments :) –  user1686230 Oct 19 '12 at 12:50
add comment

1 Answer

up vote 3 down vote accepted

To clarify this as an answer, using the setRequired()-Method on any Zend\Form\Element only declares if the HTML-Attribute required="(bool)" should be rendered or not.

If you want to exclude a Field/Element from Validation you need to define this inside your InputFilters setting 'required' => false

share|improve this answer
accepted your answer, your contributions are appreciated –  user1686230 Oct 22 '12 at 8:23
add comment

Your Answer


