A
A
Alexander Stepanov2017-09-28 17:37:15
Yii
Alexander Stepanov, 2017-09-28 17:37:15

How to get value from select in yii2?

I am making a basket ...
There is such a construction:

<p>
  <input type="number" data-id="qty" value="1" id="qty">
  <a href="<?= Url::to(['cart/add', 'id' => $product->id]) ?>" data-id="<?= $product->id ?>" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i> <?= Yii::t('app', 'Add to cart') ?></a>
</p>

Quantity field and add to cart button.
The quantity data is transferred perfectly and everything is saved where necessary, but ... it also eats attributes that the user must specify.
I decided to make a select:
<?php foreach ($attributes as $attribute): ?>
<p>
<?= $attribute->content->name ?>: 
<?php if ($attribute->getValuesCount() == 1): ?>
  <?php foreach ($attribute->values as $val): ?>
    <?= $val->content->name ?>
  <?php endforeach ?>
<?php else: ?>
  <select data-id="val" id="val" name="val[]">
    <option value="">
      Select one
    </option>
<?php foreach ($attribute->values as $val): ?>
  <option value="<?= $val->id ?>">
    <?= $val->content->name ?>
  </option>
<?php endforeach ?>
  </select>
<?php endif ?>
</p>
<?php endforeach ?>

But the select value is not passed...
I tried both the checkbox and the radio, and also framed it with the form tag - no effect...
Everything seems to be simple, but something is clearly wrong
. Tell me, please, where to dig or what example, and then nowhere

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question