2016-11-22 55 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