How to pass the data in PHP

0

I have a doubt, I am making a system of registration of orders, however when clicking the button I want these data to appear on another page (I had done in javascript but this compromises security, I wanted to know how to do in php) : example:

here the record:

Inthissecondimage,whenclickingontheabove,Iwanttoregistertheserequestshere:

<divclass="container">


<div class="last-liner">
                <p>Valor do Pedido: <span id="resultado" class="resultado"></span></p>
                <p>Taxa de Entrega: <span id="txa" class="txa">5.00</span></p>
                <p>Total: <span id="tot" class="tot"></span></p>
                <button id="finalizar" class="btn btn-round" name="finalizar" type="button">Finalizar</button>
            </div>
        </div>
    
asked by anonymous 09.05.2017 / 11:43

2 answers

0

Harakin, you did not post the codes but I know them from another question. Edit your question by putting the codes to better understand the other users of both the question and the answer.

Here is the solution for your case.

In the script add these two lines to document.getElementById("vpedido").value = parseFloat(valorTotal).toFixed(2); document.getElementById("total").value = parseFloat(valorTotal+5).toFixed(2);

HTML - included <input type="hidden" id="vpedido" name="vpedido" value="" /> <input type="hidden" id="total" name="total" value="" />

$(document).ready(function() {

  $(".pizza-add-sub").append('<div class="plus qty-pizza">+</div><div class="mines qty-pizza">-</div>');
  $(".qty-pizza").on("click", function() {

    var $button = $(this);
    var oldValue = $button.parent().find("input").val();
    if ($button.text() == "+") {
      var newVal = parseFloat(oldValue) + 1;
    } else {
      // Don't allow decrementing below zero
      if (oldValue > 0) {
        var newVal = parseFloat(oldValue) - 1;
      } else {
        newVal = 0;
      }
    }
    $button.parent().find("input").val(newVal);

    var valorTotal = 0;
    var valoresMultiplicar = 0;
    $(".qtdpedidos").each(function() {
      valorTotal += parseFloat($(this).data("preco") * $(this).val());
    })

    $(".item span").each(function() {
      valoresMultiplicar += parseFloat($(this).html());
    })

        if (valorTotal==0){
            $("#tot").text("");
            $("#resultado").text('');
        }else{
            $("#tot").text('R$'+(parseFloat(valorTotal+5).toFixed(2)));
            $("#resultado").text('R$'+parseFloat(valorTotal).toFixed(2));
            document.getElementById("vpedido").value = parseFloat(valorTotal).toFixed(2);
            document.getElementById("total").value = parseFloat(valorTotal+5).toFixed(2);

        }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><formmethod="post" action="PaginaDestino.php">  
<div class="media-body">
<div class="quantity">
  <div class="pizza-add-sub">
    <input data-preco="10.00" type="text" id="qtdpedidos" class="qtdpedidos" value="0" />
  </div>
</div>
<div class="item" class="pizza-price">
   <span id="Span1" class="pizza">P. Unit R$10.00</span>
</div>
</div>
<input type="hidden" id="vpedido" name="vpedido" value="" />
<input type="hidden" id="total" name="total" value="" />
<input type="submit" value="Submeter" name="B1">
</form>

    <div class="last-liner">
      <p>Valor do Pedido: <span id="resultado" class="resultado"></span></p>
      <p>Taxa de Entrega: <span id="txa" class="txa">5.00</span></p>
      <p>Total: <span id="tot" class="tot"></span></p>
    </div>

Page that receives the data

<?php
$vpedido = $_POST['vpedido'];
$total = $_POST['total'];
?>


<div class="last-liner">
     <p>Valor do Pedido: <span id="resultado" class="resultado"><?php echo $vpedido;?></span></p>
     <p>Taxa de Entrega: <span id="txa" class="txa">5.00</span></p>
     <p>Total: <span id="tot" class="tot"><?php echo $total;?></span></p>
</div>
    
09.05.2017 / 15:21
0

You can make the data appear within input tags, which can be placed with the parameter readonly , which causes the values to not be modified and the value with the values that appear in the first screen which are its variables.

I'll put a simple code so you understand how to do it.

The input is stylized so it does not look like an input.

.last-liner input{
  border: none;
}
<div class="last-liner">
  <form action="pagina.php" method="post">
	  <p>Valor: <input type="text" name="valor" value="5.99" readonly="readonly"></p>
	  <input type="submit" value="Finalizar">
  </form>
</div>

The part in PHP might look like this:

<?php
if (isset($_POST['valor'])) {
  $valor = $_POST['valor'];
  echo '<p> Valor: '.$valor.'</p>';
}
?>
    
09.05.2017 / 14:20