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

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(); 
Reply


Messages In This Thread
RE: when repopulate of input item insert as null - by Wouter60 - 09-18-2018, 11:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB