Uniform - Keep input values on error (array)

Hi Fellaz!

It’s me once again…

If i just have a single value everything works great.
The input field keeps the value after submitting the form.

          <div class="form-group row">
            <label for="highlight" class="col-12 col-sm-10 col-form-label">
              <?php echo $section->formHighlightName(); ?> <span class="price"><?php echo $section->formHighlightPrice(); ?></span>
            </label><!-- /.col -->
            <div class="col-sm-2">
              <input placeholder="g" class="form-control" name="highlight" id="highlight" type="number" value="<?php echo $form->old('highlight') ?>">
            </div><!-- /.col -->
          </div><!-- /.form-group row -->

Now i’m trying to keep the values in this scenario (array).

          <?php $items = $section->formProducts()->toStructure(); ?>
          <?php foreach ($items as $item): ?>
          <div class="form-group row">
            <label for="<?php echo $item->formProductName()->slug(); ?>" class="col-12 col-sm-10 col-form-label">
              <?php echo $item->formProductName(); ?> <span class="price"><?php echo $item->formProductPrice(); ?></span>
            </label><!-- /.col -->
            <div class="col-sm-2">
              <input placeholder="g" class="form-control" name="products[<?php echo $item->formProductName(); ?>]" id="<?php echo $item->formProductName()->slug(); ?>" type="number" value="<?php echo $form->old('$item->formProductName()->slug()') ?>">
            </div><!-- /.col -->
          </div><!-- /.form-group row -->
          <?php endforeach; ?>

Somehow i think my question is related to this topic:

I tried to adapt the code for my case but without any luck. ;-(

Any help would be greatly appreciated!

Saludos, Funkybrotha

That array notation for the name doesn’t make sense here, you have independet number inputs here, not an array of checkbox values.

So, the name attribute should be anything unique:

name="<?php echo $item->formProductName()->slug(); ?>"

Thanx a lot @texnixe

Still not working… then I need to change the $rules entry “products => []” to individual names too with a foreach loop? I don’t now how to replace that with unique values. ;-(

    $rules = [
  'category' => [
    'rules' => ['required'],
    'message' => 'Kategorie fehlt',
  ],
  'products' => [],
  'service' => [],
  'name' => [
      'rules' => ['required'],
      'message' => 'Name fehlt!',
  ],
  'surname' => [
      'rules' => ['required'],
      'message' => 'Nachname fehlt!',
  ],
  'message' => [],
];

Then try

name="products[]"

hm… still not working

I think… what would work… is something like:

$rules = [
  'category' => [
'rules' => ['required'],
'message' => 'Kategorie fehlt',
  ],
  'product-a' => [],
  'product-b' => [],
  'product-c' => [],
  ],
  'surname' => []
  'message' => [],
];

but I don’t know how to get the values from
my structure field into a loop producing this kind
of output.

my blueprint looks like this:

  formProductsHeadline:
    label: Products
    type: headline
    numbered: false
  formProducts:
    label: Products
    type: structure
    style: table
    columns:
      formProductName:
    fields:
      formProductName:
        label: Product name
        type: text