Using the form helper in CakePHP 1.3, I’m trying to display a list (drop-down list) which contains several duplicated value fields (in <option> tag of course), but Cake does not seem to want to let me do it, and outputs only the first occurrence of each value.
For instance, here’s the ‘options’ array of the $form->input:
array(
0 => 'description 0',
0 => 'description 1',
0 => 'description 2',
1 => 'description 3'
);
Which will output something like:
<select>
<option value="0">description 0</option>
<option value="1">description 3</option>
</select>
And I’m looking for this result:
<select>
<option value="0">description 0</option>
<option value="0">description 1</option>
<option value="0">description 2</option>
<option value="1">description 3</option>
</select>
So as feared the problem was deeper than I first thought , and it was caused by PHP which does not (obviously) allow duplicate keys.
So here’s my solution (if anyone’s interested in):
__selectOptions()from the form helper into your new helperforeach ($elements as $name => $title) {by :
foreach ($elements as $title => $name) {It’s not the best solution as if you want to update your cakephp to the latest version after doing that, you have to copy/paste the function again, and do the same trick.
How to use it:
optionsarray the other way around :array('description' => 'key);$form->input, just do$yourhelper->inputNicolas.