duanji8615 2019-04-11 15:54
浏览 109
已采纳

使用PHP将HTML值传递给url

I am fairly new to PHP and Javascript programming. Currently I am working on a checkout component for an ecommerce website. I have an amount value for a product that is inside a span element and it's changing value according to the quantity the user selects. I need to grab these two values (quantity and value) and pass them to another PHP page. What's the best approach for doing this?

enter image description here

</div> <!-- slider-nav.// -->
    </article> <!-- gallery-wrap .end// -->
        </aside>
        <aside class="col-sm-7">
    <article class="p-5">
    <h3 class="title mb-3" id="product-title">Colocar o nome do produto </h3>

<div class="mb-3"> 
    <var class="price h3 text-warning"> 
        <span class="currency">EU €</span><span class="num" id="big_valor">29.99</span>
    </var> 

</div> <!-- price-detail-wrap .// -->
<dl>
  <dt>Descrição</dt>
  <dd><p>Here goes description consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco </p></dd>
</dl>
<dl class="row">
  <dt class="col-sm-3">Modelo</dt>
  <dd class="col-sm-9">12345611</dd>

  <dt class="col-sm-3">Cor</dt>
  <dd class="col-sm-9">Azul e Branco </dd>

  <dt class="col-sm-3">Entrega</dt>
  <dd class="col-sm-9">Portugal e Espanha</dd>
</dl>

<hr>
    <div class="row">
        <div class="col-sm-5">
            <dl class="dlist-inline">
              <dt>Quantidade: </dt>
              <dd> 
                <select class="form-control form-control-sm" style="width:70px;" onchange="calcular();" id="selector">
                    <option> 1 </option>
                    <option> 2 </option>
                    <option> 3 </option>
                </select>
              </dd>
            </dl>  <!-- item-property .// -->
        </div> <!-- col.// -->

    </div> <!-- row.// -->
    <hr>
    <a href="customer_order_form.php" class="btn  btn-primary" click="sendInfo();"> Comprar </a>

</article> <!-- card-body.// -->
        </aside> <!-- col.// -->
    </div> <!-- row.// -->
</div> <!-- card.// -->
</div>
</div>

Javascript:

$(document).ready(function() {
    $(".item-gallery a").fancybox({
        'transitionIn'  :   'elastic',
        'transitionOut' :   'elastic',
        'speedIn'   :   800, 
        'speedOut'  :   200, 
        'overlayShow'   :   false,
        'cyclic'    :   true,


    }).click(function(e){
        var image_name = $(this).attr('href');  $(".img-big-wrap div a img").attr('src',image_name);

    })

}); //END OF DOCUMENT READY

function calcular(){

let select_value = document.getElementById("selector").value;
let amount = select_value*29.99;
$('#big_valor').html(amount);
}
  • 写回答

1条回答 默认 最新

  • donpb2823 2019-04-11 19:56
    关注

    You can send quantity and value to PHP and save it in a session. Then you first look for these 2 values in the session and if you won't find them then quantity and value will be your default values.

    Edit: I recommend you to send only quantity to PHP and calculate the price based on the product price you have in your database. If you send the price from your frontend and then you use it in your order, user may change the product price and you don't want that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作