I am learning on the fly and half blocked at times with some topic. I have a form with 2 buttons on my page detalle.php:
<form action="carrito.php" method="POST" name="compra">
<input name="id_txt" type="hidden" value="<?php echo $id?>" />
<input name="nombre" type="hidden" value="<?php echo $nombre?>" />
<input name="precio" type="hidden" value="<?php echo $precio?>" />
<input name="cantidad" type="hidden" value="1" />
<input name="stock" type="hidden" value="<?php echo $stock?>" />
<?php
if ($stock>0) { ?>
<div id="detalle_caja_botones">
<input class="boton_detalle" id="cancela2" name="cancelar" type="submit" value="Cancelar" />
<input class="boton_detalle" id="comprar2" name="Comprar" type="submit" value="Comprar" />
</div>
<?php }else{
echo "Producto temporalmente agotado"; ?>
<input class="boton_detalle" name="Comprar" type="submit" value="Cancelar" />
<?php
}
?>
</form>
By clicking the 1st button # cancel2, I capture the click with jquery / preventdefault and redirect to the previous page, that fits me ok.
The problem is the second button, # buy2, when clicking, I need to check that the user is logged into the system (connected PHP variable Boolean $), if it is connected, it executes the submit, if it is not connected I send it a warning and also redirect to another page or to the registration form.
I tried but without success (jquery complicates me because the variable is php), I will appreciate any help before losing the few hairs that I have left haha.
Greetings!