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条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?