vellai durai
vellai durai

Reputation: 1011

form submit only giving last value in a loop codeigniter

Here is my view

 <?php for($i=0;$i<count($acb['def']);$i++) { ?>
<input type="text" name="xyz" value="<?php echo $abc['def'][$i]?>" />?>

Here is my controller

 $xxx=$this->input->post('xyz')

Now when i submit the form the last value only gets posted to controller

then i found that the name is same for all fields so it takes last value , so i changed the input name as

name ='xyz[$i]'

Now i need to post values , How to post values with this

Upvotes: 0

Views: 288

Answers (2)

Dharmesh Ghadiya
Dharmesh Ghadiya

Reputation: 41

You use to below code...

<?php for($i=0;$i<count($acb['def']);$i++) { ?>
  <input type="text" name="xyz[]" value="<?php echo $abc['def'][$i]?>" />
?>

Upvotes: 0

Drone
Drone

Reputation: 1134

You need to send name as array rename it to 'xyz[]' here

<input type="text" name="xyz[]" value="<?php echo $abc['def'][$i]?>" />?>

Upvotes: 1

Related Questions