$form->getHttpData() can't retrieve custom keys from input arrays

Notice: This thread is very old.
medhi
Generous Backer | 255
+
0
-

I have a form with these inputs generated from database:

{foreach $items as $item}
	<input type="text" name="item[{$item->id}]" value="{$item->value}">
{/foreach}

And i would like to retrieve these by

$values = $form->getHttpData($form::DATA_TEXT, 'item[]');

Expected result should have some ids according to the database:

array(
	13 => "foo",
	46 => "bar"
)

actually the result is with default keys:

array(
	0 => "foo",
	1 => "bar"
)

Keys are gone :(

David Matějka
Moderator | 6445
+
0
-

try

$values = $form->getHttpData($form::DATA_TEXT | $form::DATA_KEYS, 'item[]');

(>=2.1.2)

Last edited by matej21 (2014-05-06 14:42)

medhi
Generous Backer | 255
+
0
-

matej21: Wow, thanks. It works.

And if this is possible, is it also possible to have multidimensional input arrays?

...
<input type="text" name="item[{$item->id}][name]" value="{$item->value}">
<input type="text" name="item[{$item->id}][desc]" value="{$item->value}">
...
David Grudl
Nette Core | 8218
+
0
-

Empty [] is supported only at the end, so you can use item[1][name] or item[name][], but item[][name] is not implemented.