athene
athene

Reputation: 578

zend framework 3 Select tag validation

I am getting the error: The input was not found in the haystack After form post. Please see the selection tag code lines below:

// Add "roles" field
    $this->add([            
        'type'  => 'select',
        'name' => 'roles',
        'attributes' => [
            'multiple' => 'multiple',
            'options'=>$this->role_desc,
             'inarrayvalidator' => false, 
             'class'=>'form-control'
        ],
        'options' => [
            'label' => 'Role(s)',


        ],


    ]); 




  // Add input for "roles" field
    $inputFilter->add([
            'class'    => ArrayInput::class,
            'name'     => 'roles',
            'required' => true,
            'haystack'=>$this->role_ids,
            'filters'  => [                    
                ['name' => 'ToInt'],
            ],                
            'validators' => [
                ['name'=>'GreaterThan', 'options'=>['min'=>1]],
                 ['name'=>'InArray', 'options'=>['haystack'=>$this-
                       >role_ids]]


            ],
        ]); 

The InArray seems to be validating well, lm just no sure what is bringing up the exception. Thank you in advance.

Upvotes: 1

Views: 516

Answers (1)

Jannes Botis
Jannes Botis

Reputation: 11242

Actually , your issue is similar to link

To solve this, change your validators definition to:

'validators' => [
          ['name'=>'GreaterThan', 'options'=>['min'=>1]],
          [
                'name' => 'Explode',
                'options' => array(
                      'validator' => [
                           'name'=>'InArray',
                           'options'=> [
                                'haystack'=>$this->role_ids
                           ]
                       ]
                )
          ]
],

Unfortunately, I do not think there is a "cleaner" way to do this. Alternately, Maybe you could use the MultiCheckbox.

Upvotes: 1

Related Questions