Answer the question
In order to leave comments, you need to log in
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>
<?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 ?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question