2016-11-22 26 views
0

我的控制器功能:与输入的数组提交表单字段

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> 
+1

那么你的问题是什么? – bassxzero

+0

我将发送3个值作为我的视图在内容字段中的数组,但在控制器中它将只显示1 .. – sani

回答

0

试试这个

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

yeh!它的工作现在.. – sani

0

你指望整个$data数组,而不是$data['content']

我相信你想在你的PHP中使用$ary_len = count($data['content']);

您还需要在HTML中将name="content"更改为name="content[]"

请看this answer以获得关于计数关联数组时会发生什么的解释。

+0

谢谢你的工作吧! – sani

+0

随时标记答案是正确的。 – Mikey