I have a list of forms to access to each of them you need to be through the click of a button with JS code.
List form in HTML:
<form name="acciones_consultar_omd_unidades" id="acciones_consultar_omd_unidades" method="POST">
<input type="text" id="campo_verificador" name="campo_verificador" value="" hidden>
<input type="text" id="id_omd" name="id_omd" value="" hidden>
<td bgcolor= "#e4f1f6" width="25"><center><a href="javascript:enviame('planilla_omd.php', '<?=$omd?>')"> Ver </a></center></td></tr>
This I do to prevent them from accessing by entering the ID in the URL.
The enviame
function is as follows:
function enviame(planillaurl, omd){
//añado el url del action al formulario
var formulario =document.getElementById("acciones_consultar_omd_unidades");
formulario.action=planillaurl;
//Agrego a ID el valor del ID que se selecciono
var omdcampo=document.getElementById("id_omd");
omdcampo.value=omd;
//Agrego el valor de 1 al consultado
var campo_verificador=document.getElementById("campo_verificador");
campo_verificador.value=1;
//Envio el formulario = acciones_consultar_omd_unidades action=planilla_omd.php?id_omd=
formulario.submit();
}
What I do is assign to the action the value of the ID that will be consulted so that it can be POSTED.
Once the query has been validated, you will be taken to the following code, where it makes the post of the verifying field.
Planilla.php:
$ver_omd= $_POST["campo_verificador"];
if ($ver_omd == 1 || $ver_omd == 2)
{
require_once '__conexion.php';
require_once '__conexion2.php';
}
else
{
echo ('<script>alert("No tiene permisos suficientes para acceder a esta parte del sistema");</script>');
echo ("<script>window.location = 'index.php';</script>");
}
The problem is that this works to see the spreadsheets within the list, but NOT for the process of generating new records.
When you finish doing a new registration there will be a JS button that redirects you like this:
generate.js
var agree=confirm("\u00BFEsta seguro que desea generar esta OMD?.");
if (agree){
document.getElementById("generando").value = 1;
document.omd.submit();
return true ;
}
else
return false ;
generate.php
$generando = $_POST["generando"];
session_start();
if ($generando == 1)
{
require_once '__conexion.php';
}
else
{
echo ('<script>alert("No tiene permisos suficientes para acceder a esta parte del sistema");</script>');
echo ("<script>window.location = 'index.php';</script>");
}
$id_omd = $stmt->insert_id; // <-- AQUI obtenemos el ID
echo ("<script>window.location = 'planilla_omd.php?omd=$id_omd';</script>");
The process in conclusion:
-
I fill in the data form.
-
I press the js button and it puts 1 in generating.
-
I enter to generate.php and if generating is 1 happens to perform the SQL statement.
-
Terminate the sentence and redirect you to planilla_omd.
When you generate a spreadsheet it only sends you the urd by URL and not the verifier field, how can I send these two data and thus pass the verification of the If?