1
When entering a value in the input text, I should consult the bank to check if it exists. If so, I should redirect to formDetails.php. If not, I should redirect to formRegister.php.
I’ve been working on it for a few hours and I can’t find a solution. HTML and Javascript are in the same file.
<!--FILTRO FLUTUANTE -->
<div id="mws-themer">
<div id="mws-themer-hide"></div>
<div id="mws-themer-content">
<div class="mws-themer-section">
<form action="" name="myForm" id="myForm" style="padding: 0; margin: 0;" method="POST">
<input type="text" name="edtMFIR" id="edtMFIR" value="" class="mws-textinput error">
</form>
</div>
<div class="mws-themer-separator"></div>
<div class="mws-themer-section">
<button type="button" onclick="submit()" class="mws-button red small" id="mws-themer-sendfilterPCD">Filtrar</button>
</div>
</div>
</div>
<script>
function submit() {
var fornDetails = "fornDetails.php";
var fornRegister = "fornRegister.php";
var result = "<?php paginaDestino($_POST["edtMFIR"]); ?>";
alert(result);
if (result) {
myForm.action = fornRegister;
} else {
myForm.action = fornDetails;
}
myForm.submit();
}
</script>
Function where I do the bank check:
function paginaDestino($edtMFIR){
$conexao = new bancodedados();
if(!empty($edtMFIR)){
$conexao->setSQL("SELECT * FROM tab_aro_pcd_riscos WHERE aro_riscos_mfir=".$edtMFIR." LIMIT 1");
$res_a = $conexao->Consultar();
$RES_MFIR = mysql_fetch_array($res_a);
if(empty($RES_MFIR)){
return false;
}else{
return true;
}
}
}
Can someone help me ?
Man, you saved my life. Could you explain to me what the hell you were really up to ?
– Alexsander Caproni
Kk ai yes, you were going into a looping, checking the php variable in javascript without it being set, in the example above I let php do all the work.
– Felipe Duarte