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 SPSS分类模型实训题步骤
  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么
  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的
  • ¥15 我看了您的文章,遇到了个问题。