pass multiple variables through url GET

0

I want to pass two variables to another page through GET. I already have one that works like this:

 <a class='fa fa-remove' href='remover.php?remover=carrinho&id=$idproduto' style='font-size:24px'></a>

But what I'm doing now is a form so the url would be the action of the form, and so it is not working because it sends the form variables and not the ones I wrote in the action, for example:

 <form action='quant.php?qtd=carrinho&id=$idproduto'>
 <div class='input-group mb-2' style='text-align: 
      center'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input class='form-control' id='qtd1' name='qtd2'type='text' 
      value='$quantidade'/>
  <div class='input-group-append'>
<div class='input-group-append'>
<button class='btn btn-outline-secondary fa fa-refresh' type='submit'><span 
     class='glyphicon glyphicon-refresh'></span> 
 </button>&nbsp;&nbsp;&nbsp;&nbsp;
  </div>
 </div>    
   </div>     
   </form>

should go to quant.php?qtd=carrinho&id=$idproduto but go to quant.php?qtd2=12

I want it to pass the $ id product and the value that the user entered into the inputbox.

    
asked by anonymous 24.06.2018 / 23:16

1 answer

2
  

This combination of passing values by url and form at the same time I do not think it works.

The only way I know is to put the values of the variables inside inputs hidden to pass via get

<form action='quant.php' method="get">
    <div class='input-group mb-2' style='text-align: center'>
    <input name='qtd' type='hidden' value='carrinho'/>
    <input name='id' type='hidden' value='<?php echo $idproduto ?>'/>
        <input class='form-control' id='qtd1' name='qtd2'type='text' value='<?php echo $quantidade ?>'/>
            <div class='input-group-append'>
                <div class='input-group-append'>
                    <button class='btn btn-outline-secondary fa fa-refresh' type='submit'>
                    <span class='glyphicon glyphicon-refresh'></span> 
                    </button>
                </div>
           </div>    
   </div>     
</form>

PHP

$qtd = $_GET['qtd'];

$id = $_GET['id'];

$qtd2 = $_GET['qtd2'];

Or

foreach ( $_GET as $chave => $valor ) {
  // $$chave cria as variáveis com os names dos elementos do formulário
  $$chave = trim( strip_tags( $valor ) );
}

echo $qtd;

echo $id;

echo $qtd2;
    
25.06.2018 / 00:11