I'm doing a page with a main view, which has the search button, load user and show user list.
All finally end up calling the controller that has functions according to value
of the buttons. They work perfect for me, except for the user list, which tells me:
undefined index btn
in all the lines where this btn
in the main controller (not only in the list of users), when in the rest of the btn does not tell me that!
Home
<h1>Sistema de Gestion de Multas</h1>
<a href="altapersonas.html"><button class="btn btn-default" type="submit" name="btn" value="cargar">Cargar usuario</button></a> //Esto me lleva a la pagina de alta personas, la cual llama a la controladora desde el action del formulario
<form method="post" action="../controladoras/controladoraprincipal.php">
//formulario
<button type="submit" class="btn btn-info" name="btn" value="agregar">Agregar</button>
When it arrives at the controller, it knows what to do by
if ($_POST["btn"] == "agregar")
{
if (empty($_POST['nombre']) || empty($_POST['apellido']) || empty($_POST['dni']) || empty($_POST['direccion']) || empty($_POST['fechanacimiento']))
throw new Exception('Debe pasar todos los valores');
$nombre = $_POST['nombre'];
$apellido = $_POST['apellido'];
$dni = $_POST['dni'];
$direccion = $_POST['direccion'];
$fechanacimiento = $_POST['fechanacimiento'];
$persona1 = new Persona ($nombre, $apellido, $dni, $direccion, $fechanacimiento);
$daop->agregar($persona1);
$listado = $daop->todas();
require_once ('../vistas/listadeusuarios.php');
}
And that's how it works perfect. Now, when I direct direct from the main view to the controller with the "User list" button:
<a href="../controladoras/controladoraprincipal.php">
<button class="btn btn-default" type="submit" name="btn" value="lista">Listado de usuarios
</button></a>
main controller
$daop= new PersonaJsonDao();
if ($_POST["btn"] == "lista")
{
$listado = $daop->todas();
require_once('../vistas/listadeusuarios.php');
}
The result is
Notice: Undefined index: btn in C: \ wamp \ www \ projectmultiples \ controllers \ mastertrader.php on line 13 Call Stack Time Memory Function Location 1 0.0019 149288 {main} () .. \ controlerprincipal.php: 0
And it marks me that this error is in all the lines where this btn
. However, in the rest of the lines where this percentage is%, when I use it, that error does not mark me.