在产品卡页面上获取所选选项

问题描述 投票:0回答:1

我试图获取产品属性的选定选项

              <form method="post">
                <!-- Check if there are attributte 1 of the product -->
                <?php if (($product['Attribute 1 value(s)'] == '') == False): ?>

                <div class="form-group">
                  <label for="size" id="size"><?= $product['Attribute 1 name']; ?></label>

                  <select name="atr1" id="size" class="form-control">
                    <!-- For each Attribute 1 value make an option -->
                    <?php foreach ($option_array_1 as $option_value)
                    {
                      echo "<option value=".$option_value.">".$option_value."</option>";
                    }
                    ?>
                  </select>

                </div>

                <?php endif; ?>

              </form>

php$_SESSION['atr1'] = $_POST['atr1'];

但是,当我尝试获取该值时,发生错误:注意:未定义的索引:atr2

如何在用户按下购买按钮之前将atr1值保存在Session变量中?

php html forms post html-select
1个回答
0
投票

使用onchage事件并在jquery中获取所选值,然后使用ajax调用php函数调用ajax并将所选值存储到$_SESSION['atr1']中要么如下使用$_SESSION['names'] = array(); array_push($_SESSION['names'],$name);

© www.soinside.com 2019 - 2024. All rights reserved.