I have a form on the main page to update balances and another in a modal window to register purchases, like this:
<!-- Con este botón llamo al modal Registrar Compras-->
<button class="btn btn-primary" data-toggle="modal" data-target="#modalRegistrarCompras">
Registrar Turno
</button>
<!-- Formulario para Actualizar Saldos -->
<form role="form" method="post">
<button type="submit" name="actualizarSaldos" class="btn btn-danger">
Actualizar Saldos
</button>
<!-- Todos los campos del formulario para actualizar saldos-->
<?php
$ActualizarSaldos = new ControladorSaldos();
$ActualizarSaldos -> ctrActualizarSaldos();
?>
</form>
<!-- Modal Registrar Compras -->
<div id="modalRegistrarCompras" class="modal fade" role="dialog">
<form role="form" method="post" autocomplete="off">
<!-- Todos los campos del formulario para registrar compras-->
<button type="submit" class="btn btn-primary">
Registrar Compras
</button>
<?php
$registrarCompra = new ControladorCompras();
$registrarCompra -> ctrRegistrarCompras();
?>
</form>
</div>
The idea is to register several purchases from the modal and then update balances once from the main page.
Note that the two controllers are different.
The problem I have is that when registering a purchase, the balance controller is executed and not the purchase controller. I came to this conclusion after commenting out these two lines of code:
<?php
//$ActualizarSaldos = new ControladorSaldos();
//$ActualizarSaldos -> ctrActualizarSaldos();
?>
The two actions separately work , that is, with these two lines of code commented out, purchases through the modal are recorded correctly. Then, if I want to update balances, I enable these two lines of code and the balances are updated correctly.
My Doubt is:
What do I need to change in the code so that both forms insert the information independently in the table that corresponds to them, without the two controllers conflicting?
Your problem is that you have both actions in the same file. and both point to the same path. It doesn't matter which form it arrives from, the 2 actions that you have declared in your file are always executed.
uses. values for each button and so you will know in the execution of the script which button was touched.
Something like for example: