Values of input fields in the same array

Today, Petr Vytlacil asked me how to create input fields with the html helper so that the values are in the same array, i.e. how to create something like:

<input name="data[Price][price][]" value= "" />
<input name="data[Price][price][]" value= "" />

The obvious approach with


does not work, as it creates a wrong name:

<input  name="data[Price][price[]]" value="" />

If we look at this output, we can see, how CakePHP works: it splits “Price/size[]” on the “/” character and adds square brackets. That leads us to the following workaround:


Sure, it is a little bit counterintuitive, but it does the job ;-)



  1. Posted February 15, 2006 at 11:22 pm | Permalink

    Hi Daniel I want one more say thanks for your advice. It would be best write tutorial how generate inputs with the aid of AJAX. For examples any item can has many price after capacity. So this generate dozens of times inputs for setting price and capacity.

    Ciao and tomorrow I wish your national hockey team luck. Because our magic player with No. 68 will have shooting day .-). So I hope.
    Petr Vytlačil – Czech Republic

  2. luke barker
    Posted February 16, 2006 at 2:52 pm | Permalink

    how about for a checkbox ?

    this works for the name, but it breaks on the id ! In that:

    echo $html->checkbox(‘Category/Category][‘, NULL, array(‘value’=>$catid));

    Gives us:

  3. luke barker
    Posted February 16, 2006 at 2:54 pm | Permalink

    input type=”checkbox” name=”data[Category][Category][]” id=”tag_Category][” value=”1″

    sorry cant work out how to do a html tag!

Post a Comment

Required fields are marked *

%d bloggers like this: