How to pass data in PHP

Asked

Viewed 82 times

0

I have a question, I’m making a system for registering orders, but when clicking the button I want this 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:

inserir a descrição da imagem aqui

In this second image, when clicking finish, above, I want the record of these requests to appear here:

inserir a descrição da imagem aqui

<div class="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>
  • 1

    That’s not necessarily PHP. You need to learn the basics of the method (method attribute) attribute of FORM in HTML. The PHP captures this data sent by FORM in a array and then becomes easy to use or show. It is also possible to do POST with JavaScript, but this already seems to me too advanced for you...

2 answers

0

You can cause the data to be displayed within tags input, which can be placed with the parameter readonly that the values are not modified and the value with the values that appear on the first screen that are your variables.

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

Input is stylized so it doesn’t 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 PHP part can be like this:

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

0


Harakin, you didn’t post the codes but I know them from another question. Edit your question by placing the codes for better understanding of other users of both the question and the answer.

Here’s the solution to your case.

In the script add these two lines
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>

<form method="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 receiving 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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.