提交包含输入字段数组的表单

时间:2016-11-22 12:55:34

标签: php codeigniter

我的控制器功能:

public function c_content()
{
    $data['story_id']=$this->input->post('story_id');
    $data['template_id']=$this->input->post('template_id');
    $data['content']=$this->input->post('content');
    $ary_len=count($data); // give me output 1 where as i send 3 value 
    echo $ary_len;
}

从这里发送值故事ID,模板ID和内容,其中内容具有多个输入值。

我的观点:

<form action="<?=base_url('c_signup/c_content')?>" method="post" >
    <input type="text" name='template_id' value=<?php echo  $template_id ?> >
    <input type="text" id="story_id" name='story_id' value=<?php echo $story_id ?> >

    <div class="abc">

    <?php
        $story_content1=$txt;

        // here some code is exected and give me result 3
        $result = count($out); // output 3

        for ($x = 0; $x < $result; $x++) {
            echo("
                  <input type='text' value='". $out[$x] ."' name='content'>// here i set name of txt field as content
            ");
    ?>
    <?php
        }
    ?>

    </div>
    <button value="submit">save</button>
</form>

2 个答案:

答案 0 :(得分:0)

试试这个

<input type='text' value='". $out[$x] ."' name='content[]'>

答案 1 :(得分:0)

您正在计算整个Workbook_BeforeSave数组,而不是$data

我相信你希望PHP中有$data['content']

您还需要在HTML中将$ary_len = count($data['content']);更改为name="content"

查看this answer,了解计算关联数组时会发生什么的解释。