I create fields like this:

for($i = 0; $i < count($rows); $i++) { echo CHtml::label($rows[$i]['name'], $rows[$i]['name']); echo CHtml::textField('elem[]','',array('id'=>$rows[$i]['name'])); } 

And in the controller:

 foreach($_POST['elem'] as $check) { $Ids = $_POST['elem']; }; 

So here I get:

 array(2) { [0]=> string(3) "231" [1]=> string(1) "4" } 

And how to find out the id field?

  • What id? Which was set as an attribute: array('id'=>$rows[$i]['name']) ? - romeo
  • Your loop at each iteration calls count($rows) . Correct: for($i = 0, $cnt = count($rows); $i < $cnt; $i++) {} - romeo

1 answer 1

Although crooked, but it works

_form

  echo CHtml::textField("elem[$id][val][]", $val, array('id' => $rows[$i]['name'])); 

In the controller:

  $Ids = $_POST['elem']; echo '<pre>'; var_dump($Ids); 

And I get:

  array(10) { [4]=> array(1) { ["val"]=> array(1) { [0]=> string(5) "10000" } } [3]=> array(1) { ["val"]=> array(1) { [0]=> string(3) "351" } } [5]=> array(1) { ["val"]=> array(1) { [0]=> string(3) "100" } } 
  • one
    To supplement your question, please use the edit option. The "Post an Answer" button should only be used for comprehensive answers to questions. - romeo