Call method in action of a form that invokes which page should be redirected

1

When entering a value in the input text, I should check the database to see if it exists. If so, should I redirect to formDetails.php. If not, I should redirect to formRegister.php.

I've been working on this for a few hours and can not find a solution. HTML and Javascript are found 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 check in the bank:

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 anyone help me?

    
asked by anonymous 21.09.2017 / 15:52

2 answers

0

I solved the various errors that I found, likely to work that way.

<?php 

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)){
        header('Location: fornRegister.php');//não seria form?
    }else{
        header('Location: fornDetails.php');
    }
}

}

if(isset($_POST['edtMFIR'])){paginaDestino($_POST['edtMFIR'])}

?>

<!--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 myForm = document.getElementById('myForm');

            myForm.submit();

        }
    </script>
    
21.09.2017 / 16:11
0

I've done this recently using JQuery and Ajax, the function you're looking for is .keyup my example:

// Essa função verifica se o email ja existe e desabilita o botão 
function verif_email(email,nome) {
    var html = '<br>Você é o : \"' + nome + '\" ? <a href="#">Sim</a> / <a href="#">Não</a>';
    //essa condição é para caso a pagina ja carregue com um email no campo
    $('#email').ready(function() {
        if ($('#email').val() == email){
            $('#btn1').prop('disabled', true);
            $('#btn1').html("Email ja cadastrado");
            $('#texto').html(html);
        }else{
            $('#texto').hide();
        }
    });

    //essa condição é para ele checar cada vez que digitar
    $('#email').keyup(function() {
        if ($('#email').val() == email){
            $('#btn1').prop('disabled', true);
            $('#btn1').html("Email ja cadastrado");
            $('#texto').show();
            $('#texto').html(html);
        }else{
            $('#btn1').show();
            $('#btn1').html("Salvar");
            $('#btn1').prop('disabled', false);
            $('#alert').hide();
            $('#texto').hide();
        }
    });
}
function load_json() {
$.ajax({
    url : "json.json",
    success : function(result) {
        verif_email(result["email"],result["nome"]);
        setTimeout(function(){load_json();}, 100);
    }
});

}

I hope I have helped.

    
21.09.2017 / 16:23