how could I check if the person clicked on a button

Asked

Viewed 45 times

0

<button class="btt"><a href="carrinho.php?prod=<?= $skins['id_skin']?>">Comprar</a></button>

good i wanted to check if the person really clicked on the button and if the get = cart.

  • The <a> can’t be inside a <button>.

  • how would it be then? I wanted to check if the people really clicked the button.

  • if he clicked the button I would do an if for him to grab the id, and check if there is an item session.

  • it’s not, I just created the same button.

  • @sam and how would I check the get? sends an answer so that I can vote for her as a positive bro.

1 answer

-1


The element <a> shall not be descended from the <button>.

You can include one more URL parameter with a value name carrinho:

carrinho.php?prod=<?=$skins['id_skin']?>&clique=carrinho

In PHP you check if the parameter clique is equal to carrinho:

$prod = $_GET['prod'];
$clique = $_GET['clique'];

// $clique igual a "carrinho" e $prod não é vazio
if($clique == "carrinho" && !empty($prod)){
   // fazer algo
}
  • https://jsfiddle.net/cr5aqznd/ mano vc can tell me if I had the right logic?

  • I created an if to check if there is no session items (which is an array) is pq has no product, otherwise it will add ( pq has already added product).

  • It looks ok, but it’s good to always test.

Browser other questions tagged

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