Low-level forms how to get values of the multiple inputs?

9 months ago

asinkan
Member | 23
+
0
-

Hello,
I needed dynamically made forms. I found that Low-level forms can help me. But I do not understand how to get values inside of the forms. I have table

<td> {$day} </td>
<td> <input type=textbox name="sel[]"> </td>
<td> <input type=textbox name="sel[]" ></td>
<td> <input type=submit name="sel[]" value="Send"> </td>

I need to get values inside of the fields. I found this…

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

But how should my function in Presenter look like? How will be that submit connected with all inputs?

Thx

9 months ago

Ondřej Kubíček
Member | 290
+
+1
-

I think that you want to edit & save every row separately, right?

You should use Multiplier

9 months ago

asinkan
Member | 23
+
0
-

Ondřej Kubíček wrote:

I think that you want to edit & save every row separately, right?

You should use Multiplier

Yes, thank you. That is what I needed. I can get the data.

My other pain is that some of the values will be already filled in, some will be empty. Like in this screenshot

I know,in normal forms, I can use this:

$form->addText('tag', '');
$form['tag']->setDefaultValue("my preset value");

But how to fill this forms?
My Presenter, for simplification only one text input:

protected function createComponentShopForm()
{
    return new Multiplier(function ($itemId) {
        $form = new Nette\Application\UI\Form;
        $form->addText('tag', '');

        $form->addHidden('itemId', $itemId);
        $form->addSubmit('send', 'Add to cart')
        ->onClick[] = [$this, 'shopFormSucceeded'];
        return $form;
    });
}

My latte:

{foreach $days as $day}
    {$day} {control shopForm-$day}
{/foreach}

Thank you.

Last edited by asinkan (2018-01-29 23:32)

9 months ago

Ondřej Kubíček
Member | 290
+
+1
-

you know $itemId so you can easily use something like this

return new Multiplier(function ($itemId) {
    ...
    $row = $context->table('days')->get($itemId); //or whenever you store data
    $form->addText('tag', '')->setDefaultValue($row->tag);
    ...
});