validating mutiple drop downs list with the same name field in CakePHP 2.x -


i'm new cakephp 2x. have multiple drop down in form. drop downs using same list data, 1 table called -> students. want ,when user select first student in first drop down ,then student should minus next 4 drop down or disabled in next 4 drop downs.so user wouldn't able add same student repeately. plz help! thanks! in advance.

      //here controller add file:         public function add(){         if ($this->request->is('post')) {      $this->group->create()    if ($this->group->save($this->request->data)) {             $this->session->setflash(__('the group has been saved.'));             return $this->redirect(array('action' => 'index'));         } else {             $this->session->setflash(__('the group not saved.  please, try again.'));         }      }       $this->loadmodel('student');     $student1s = $this->student->find('list');      //pr ($student1s);      $this->set(compact('student1s'));   }  // here add.ctp   < div class="groups form">   <div class="row">     <div class="col-md-12">         <div class="page-header">             <h1><?php echo __('add students'); ?></h1>         </div>     </div> </div>    <div class="row">     <?php echo $this->form->create('groups', array('role' => 'form')); ?>     <div class="col-md-5 col-md-offset-3">               <div class="form-group">                 <?php echo $this->form->input('0.name',  array('type'=>'select','options'=>$student1s,'empty' => 'please choose  student','class'=>'form-control'));?>             </div>             <div class="form-group" >                 <?php echo $this->form->input('1.name',  array('type'=>'select',"options"=>$student1s,'empty' => 'please choose  student','class'=>'form-control',));?>             </div>             <div class="form-group">                 <?php echo $this->form->input('2.name', array('type'=>'select',"options"=>$student1s,'empty' => 'please choose   student','class'=>'form-control'));?>             </div>               <div class="form-group">                 <?php echo $this->form->input('3.name', array('type'=>'select',"options"=>$student1s,'empty' => 'please choose  student','class'=>'form-control'));?>             </div>             <div class="form-group">                 <?php echo $this->form->input('4.name', array('type'=>'select',"options"=>$student1s,'empty' => 'please choose  student','class'=>'form-control'));?>             </div>                 <div class="form-group">                 <?php echo $this->form->submit(__('submit'), array('class'  => 'btn btn-primary')); ?>             </div>          <?php echo $this->form->end() ?>      </div><!-- end col md 12 -->   </div><!-- end row -->  </div> 

find solution problem avoid duplication of data,this link helps -> validating multiple fields same name. have put code ->array('validate' => 'true')<- in line
if ($this->group->save($this->request->data),array('validate' => 'true')) {

and done no need disable selected list value.


Comments