Welcome Guest, Not a member yet? Register   Sign In
when repopulate of input item insert as null
#7

(This post was last modified: 09-19-2018, 02:02 AM by kvanaraj.)

(09-18-2018, 11:09 PM)Wouter60 Wrote: Your greatest challenge is: how to repopulate only the fields that were enabled.

If you carefully study my last reply, you will see that the names of the input fields aren't just noc[] or cbx[], but the id of the current row is used as the key of the element.
Field arrays without a user defined index, automatically get a numeric key starting with 0 in the $_POST data.

Let's say you have 5 fields named "noc[]", and you only enable the second and fifth. In $this->input->post('noc') you will see just 2 elements being returned: noc[0] and noc[1]. So it's impossible to find out which ones were posted.

If the 5 fields have the names "noc[1]", "noc[2]", "noc[3]", "noc[4]" and "noc[5]", now after you post the form, $this->input->post('noc') will hold noc[2] and noc[5].

You can dynamically assign the keys of noc[…]  in your foreach {}  structure and repopulate them with set_value():
(View)
PHP Code:
<?php foreach ($certs as $cert) : ?>
   <tr>
     <td><?= form_input(array( 'name' => 'noc[' $cert['id'] . ']''value' => set_value('noc[' $cert['id'] . ']'$cert['noc']));?></td>
   </tr>
<?php endforeach; ?>

A good way to find out what's in the $_POST data is this:
PHP Code:
echo '<pre>';
print_r($_POST);
echo 
'</pre>';
die(); 
i ve attached my View. kindly change according to my requirement


Code:
$data['getcert1'] = $this->User_Model->getcert1($appno);
 $data['getcert2'] = $this->User_Model->getcert2($appno);
 $data['getcert3'] = $this->User_Model->getcert3($appno);
 $data['getcert4'] = $this->User_Model->getcert4($appno);
 $data['getcert5'] = $this->User_Model->getcert5($appno);

Model
Code:
public function getcert1($appno)
{
 $regno = $this->session->userdata('username');
 $this->db->select('id,certificate_id,fee,APPNO,regno,certid,noc , sum(noc*fee) as paid');
// $this->db->select('*');
 $this->db->from('certificate_det');
 $this->db->where('appdet.regno',$regno);
 $this->db->where('appdet.appno',$appno);
 $this->db->where('certificate_det.certificate_id',1); // based on
 $this->db->join('appdet', 'appdet.certid = certificate_det.certificate_id', 'left');
 $query = $this->db->get();
 return $query->result_array();
 echo $query;  
   }

Code:
public function getcert2($appno)
{
 $regno = $this->session->userdata('username');
 $this->db->select('id,certificate_id,fee,APPNO,regno,certid,noc , sum(noc*fee) as paid');
// $this->db->select('*');
 $this->db->from('certificate_det');
 $this->db->where('appdet.regno',$regno);
 $this->db->where('appdet.appno',$appno);
 $this->db->where('certificate_det.certificate_id',2);
 $this->db->join('appdet', 'appdet.certid = certificate_det.certificate_id', 'left');
 $query = $this->db->get();
 return $query->result_array();
 echo $query;  
   }
Code:
Controller
********
$certids = $this->input->post('certid');  //here you leave the [ ] out!
    $nocs = $this->input->post('noc');
    $result = array();
    foreach ($certids as $index=>$certid)
 {
       $result[] = $certid . '_' . $nocs[$index];
    }

 echo '<pre>';
 print_r($result);
 echo '</pre>';
    $date = new DateTime("now");
    $today = $date->format('Y-m-d');

    foreach($result as $value)
       {
       list($certid,$noc) = explode ('_',$value);
        $insert = array();
       $insert[] = array(
           'appno' => $appno,
           'regno' => $regno,
          'certid' => $certid,
             'noc' => $noc,
             'date' => $today
               );      
     
       $this->load->model('user_Model');
       $this->User_Model->studreginsert($insert);        
      }


Attached Files
.php   application.php (Size: 7.7 KB / Downloads: 27)
Reply


Messages In This Thread
RE: when repopulate of input item insert as null - by kvanaraj - 09-19-2018, 12:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB