Welcome Guest, Not a member yet? Register   Sign In
hi, i have a view with several demands and the problem is that only saves the last one from the foreach
#1

[eluser]dinisptc[/eluser]
hi, i have a view with several demands and the problem is that only saves the last one from the foreach





Code:
<?php echo form_open("demand/edit_demand_meet/{$this->uri->segment(3)}/{$this->uri->segment(4)}"); ?>

  
      <?php foreach($demands as $dem)
                {?>
                  
                
                <div id="demandUID" class="prefBloc">

              
                         &lt;input type="hidden" name="demanduid" value="&lt;?php echo $dem['uid']; ?&gt;" /&gt;
   &lt;!--<h3>--&gt;
                        <p>
                        <h3> NÂș &lt;?php echo $dem['number']; ?&gt; </h3>
                        </p>
                        <p>
                      
                       <h3>
                        &lt;input type="text" name="demandname" id="demandname" placeholder="&lt;?php echo $ts395 //demand ?&gt;" value="&lt;?php echo $dem['name']; ?&gt;" /&gt;
                       </h3>
                        </p>
                        &lt;!--</h3>--&gt;
                        
   <p>&lt;input type="text" name="description" id="description" placeholder="&lt;?php echo $ts396 //description ?&gt;" value="&lt;?php echo $dem['description']; ?&gt;" /&gt;&lt;?php //echo $dem['description']; ?&gt; </p>
  </div>
            
&lt;?php } //demands?&gt;  
                &lt;input type="submit" class="submit" value="&lt;?php echo $ts380 //save ?&gt;" /&gt;



here is the controller

Code:
function edit_demand_meet()
    {
        
               if (!$this->ion_auth->logged_in())
        {
   //redirect them to the login page


   redirect('user/login', 'refresh');
  }
  elseif (!$this->ion_auth->is_admin())
                {
            $group = 'architect';
            $groupmembers = 'members';
            if (($this->ion_auth->in_group($group))or($this->ion_auth->in_group($groupmembers)))
            {

              $this->load->helper(array('form', 'url'));

       $this->load->library('form_validation');
                    
                        //$this->load->view('formsuccess');
   // get the user object      
   $data->the_user = $this->ion_auth->user()->row();
              // put the user object in class wide property---&gt;----&gt;-----
              $this->the_user = $data->the_user;
            
              // load $the_user in all displayed views automatically
              $this->load->vars($data);


   //set the flash data error message if there is one
   $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
  
   $DContent['page_details'] = array('page_title' => 'Index of freejoBoard');
   $Dmeta = array('meta_title'=>'Welcome to Onplans','meta_descricao'=>'onplans');
          $Dheader = array();
          $Dsidebar = array();
          $Dfooter = array();
                                  
   //$dueDate =$this->input->post('dueDate');
                        
                        $demand_uuid =$this->input->post('demanduid');
                        $demandname =$this->input->post('demandname');
                        $description =$this->input->post('description');    
                        
                        print_r($demand_uuid);
                        
                        $task_uuid =$this->input->post('taskuid');
                        $taskname =$this->input->post('taskname');        
                                
                        $this->task_model->update_task_meet($task_uuid,$taskname);
                                                                        
                        
                        $this->demand_model->update_demand_meet($demand_uuid,$demandname,$description);
                        
                        
                        $this->data['message']='saved successfuly';
                        
                        $projectUID=$this->uri->segment(3,0);
                        $meetingUID=$this->uri->segment(4,0);

                        //$Ddata['timeline']=$this->timeline_model->listar_timeline_onlyreports(0,0,$projectuid);

                        $this->data['meetproj']=$this->timeline_model->listar_project_meeting($projectUID,$meetingUID);
                        $this->data['meetpresences']=$this->timeline_model->listar_presences_contractors($meetingUID);
                        //demands
                        $this->data['demands']=$this->timeline_model->listar_timeline_demands($projectUID);

                        //preenche as variaveis
                        $this->template->write_view('meta', 'html/meta',  $Dmeta, true);
                        $this->template->write_view('head', 'html/head_index');
          $this->template->write_view('header', 'html/header', $Dheader, true);                                                                              
                                                                                                                    
                        $this->template->write_view('content', 'onplans/list_my_project_meeting', $this->data, true);
                        //$this->template->write_view('content', 'onplans/success_edit_demand',$this->data,true);
          $this->template->write_view('sidebar', 'html/sidebar_user');
          $this->template->write_view('footer', 'html/footer');
          $this->template->render();
        
                   }
                  
                }
                else
                {
                   redirect('user/login', 'refresh');
                }
        
    }


I have to find a way to edit each demand separately , what its happening is only i can save the last one from the loop

thanks
#2

[eluser]CroNiX[/eluser]
It probably has something to do with you creating your form inputs in a loop. Each one has the SAME name. In HTML, if form elements have the same name (and aren't an array), then only the last one will be used. Either make it so that the name gets altered with each loop, or change the inputs to be an array, like:
Code:
&lt;input type="hidden" name="demanduid[]" /&gt;
Notice the [] after the name.

Now $this->input->post('demanduid') will be an array of multiple values.




Theme © iAndrew 2016 - Forum software by © MyBB