addElement('Select', 'Category',array( 'labe...">

Why am I getting the error "0" not found in the haystack "?

I have two dependent fields:

 $this->addElement('Select', 'Category',array(
         'label'      => 'Category:',
         'AutoComplete'=> true,              
         'multiOptions' => array('0' => '-Category-',$a->GetCategories(),'2' => '-Add             category-'),
         'required' => true ));

  $this->addElement('Select', 'SubCategory',array(
          'label'      => 'Sub Category:',
          'AutoComplete'=> true, 
          //'multiOptions' => array('0' => '-Select Category-'),
          'required' => true )); 

I want to display the contents of the second, so in the controller I do the following:

     if ($this->getRequest()->isPost()) {  //Le formulaire est-il posté ?
     $formData = $this->getRequest()->getPost(); // récupère les infos des formulaires

     if ($form->isValid($formData)) { //Si le formulaire passe la validation
     $v = $form->getValues(); // On récupère les données du formulaire

     $Category= $v['Category'];
     $a=$form->getElement('Category')->getMultiOption('1');
     $cat=$a[$Category];

     $SubCategory =$v['SubCategory '];
     $b=$form->getElement('SubCategory')->getMultiOption($SubCategory);

     $this->view->test =  $b ;


     }

     else {$form->populate($formData);}

    /*Appel du web service d'authentification*/    
  }

When I click the submit button, the second summary becomes empty, and I get:

'0' not found in haystack

Can someone explain why this is?

+3
source share
3 answers

The error message is in the validator inArray. You can disable it by setting the appropriate key for the selected item:

'registerInArrayValidator' => false
+10
source

You violate the concept of MVC by invoking echofrom a controller class. The action controller should not produce any output. Only submission should do it!

0

validator forArray . , , .

0

All Articles