douqihua6212 2015-12-03 04:40
浏览 45
已采纳

Codeigniter从数组字段中获取表单字段值不起作用

I want get post fields value in my View, but all form did not get the value as well, i get an "Array" string in my form View when i click submit button.

enter image description here

I declared the fields in array => Controller :

$data6 = array(
     'no_lab'                    => $no_lab[$i],
     'low_sampling'              => $low_sampling[$i],
     'sampling_point'            => $sampling_point[$i],
     'sampling_tgr'              => $sampling_tgr[$i],
     'sampling_clk'              => $sampling_clk[$i],
     'sampling_analys'           => $sampling_analys[$i],
     'shift'                     => $shift[$i]
 );

And in my View i've set "set_value('array[]')", like this:

<td>
   <input type="text" name="no_lab[]" id="no_lab" value="<?php echo set_value('no_lab[]'); ?>" required/></td>
<td>
   <input type="text" name="low_sampling[]" id="low_sampling" value="<?php echo set_value('low_sampling[]'); ?>"/></td>
<td>
   <input type="text" name="sampling_point[]" id="sampling_point" size="17" value="<?php echo set_value('sampling_point[]'); ?>"/></td>
<td>
   <input type="text" name="sampling_tgr[]" id="sampling_tgr" value="<?php echo set_value('sampling_tgr[]'); ?>"/></td>
<td>
   <div class="input-group clockpicker col-sm-12" data-autoclose="true" data-time-format="HH:mm">
     <input type="text" name="sampling_clk[]" id="sampling_clk" value="<?php echo set_value('sampling_clk[]'); ?>" required/>
       <span class="input-group-addon">
       <span class="glyphicon glyphicon-time"></span></span>
   </div>
</td>
<td>
   <input type="text" name="sampling_analys[]" id="sampling_analys" value="<?php echo set_value('sampling_analys[]'); ?>"/></td>

reference to CI re-populating form: https://www.codeigniter.com/user_guide/libraries/form_validation.html

So, am i doing it wrong? i'm new to CI.

  • 写回答

3条回答 默认 最新

  • dpq39825 2015-12-03 07:54
    关注

    Print_r of your array returns a value. so make your $a=set_value('no_lab[]');. hence $a is array. I think count($a) returns 1, therefore i am using echo $a[0]; now try the code

    <td>
    <input type="text" name="no_lab[]" id="no_lab" value="<?php $a=set_value('no_lab[]'); echo $a[0]; ?>" required/></td>
    <td>
    <input type="text" name="low_sampling[]" id="low_sampling" value="<?php  $a=set_value('low_sampling[]');echo $a[0];  ?>"/></td>
    <td>
    <input type="text" name="sampling_point[]" id="sampling_point" size="17" value="<?php $a= set_value('sampling_point[]');echo $a[0];  ?>"/></td>
    <td>
    <input type="text" name="sampling_tgr[]" id="sampling_tgr" value="<?php $a= set_value('sampling_tgr[]'); echo $a[0]; ?>"/></td>
    <td>
    <div class="input-group clockpicker col-sm-12" data-autoclose="true" data-time-format="HH:mm">
    <input type="text" name="sampling_clk[]" id="sampling_clk" value="<?php $a= set_value('sampling_clk[]');echo $a[0];  ?>" required/>
    <span class="input-group-addon">
    <span class="glyphicon glyphicon-time"></span></span>
    </div>
    </td>
    <td>
    <input type="text" name="sampling_analys[]" id="sampling_analys" value="<?php $a=set_value('sampling_analys[]');echo $a[0];  ?>"/></td>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 ansible连接设备报错
  • ¥60 pmsampsize包取值问题
  • ¥15 波形合成电路的设计学习
  • ¥15 unity脚本挂不上
  • ¥15 数学建模数学建模需要
  • ¥20 Java Sound Api 调用Mixer.getLine偶现Line unsupported错误。
  • ¥15 使用cuda加速opencv运算但是报错AttributeError: module 'cv2.cuda' has no attribute 'getCudaEnabledDeviceCount'
  • ¥15 java输入输出异常
  • ¥15 三子连珠对弈小游戏制作
  • ¥15 C++扑克牌游戏的编程