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 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题