简体   繁体   中英

Value passing as null from view to controller

The id is passing correctly but the post value is returning as empty , Please suggest with a solution what mistake i am doing here

Here is my view

 <?php for($i=0;$i<count($array['value']);$i++) { ?>
 <?php $id= $room['value'][$i]['Index'];  ?>
<ul >
   <li>
   <?php echo form_open('cont/arraylist/'.$id); ?>
   <input type="hidden" name="<?php echo 'foo'.$i ?>" value="<?php  echo $room['value'][$i]['foo']?>" />
   <input type="hidden" name="<?php echo 'boo'.$i?>" value="<?php  echo $room['value'][$i]['boo']?>" />
   <input type="hidden" name="<?php echo 'bar'.$i?>" value="<?php  echo $room['value'][$i]['bar']?>" />
   <input type="hidden" name="<?php echo 'baba'.$i?>" value="<?php  echo $room['value'][$i]['baba']?>" />                                     
   <input type="submit" />
   <?php echo form_close(); ?>
   </li>
 </ul>
 <?php } ?>

Here is My controller

function arraylist($id) 
   {
   echo $id;
   echo $this->input->post('foo'.$id); 
   echo $this->input->post('boo'.$id); 
   echo $this->input->post('bar'.$id);
    echo $this->input->post('baba'.$id);

 }

You are trying get the input name 'foo'.$id but in view you are concatenating 'foo'.$i . This occurs to all. Do this:

<input type="hidden" name="<?php echo 'foo'.$id ?>" value="<?php  echo $room['value'][$i]['foo']?>" />
<input type="hidden" name="<?php echo 'boo'.$id?>" value="<?php  echo $room['value'][$i]['boo']?>" />
<input type="hidden" name="<?php echo 'bar'.$id?>" value="<?php  echo $room['value'][$i]['bar']?>" />
<input type="hidden" name="<?php echo 'baba'.$id?>" value="<?php  echo $room['value'][$i]['baba']?>" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM