1

Estou tentando executar uma função PHP após o submit da página, mas não venho obtendo sucesso. Alguém poderia me ajudar?

    <?php
function teste() {
?>
    <div>
        <p>
            <?php echo "Foi clicado"; ?>
        </p>
    </div>
<?php   
}
?>

<body>       

    <!--FILTRO FLUTUANTE -->
    <div id="mws-themer">
        <div id="mws-themer-hide"></div>
        <div id="mws-themer-content">
            <div class="mws-themer-section">
                <form action="?a=ok" 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="submit" class="mws-button red small" id="mws-themer-sendfilterPCD">Filtrar</button>
            </div>
        </div>
    </div>

    <?php
        if (isset( $_GET['a'] ) && $_GET['a'] == 'ok' && $_POST['texto'] != '') {
            teste();
        }
    ?>
0

1 Resposta 1

1

Seu botão de submit está fora do form, para arrumar coloque-o dentro da tag form, caso isso afete alguma coisa no seu layout, submeta através do javascript exemplo...

<!--FILTRO FLUTUANTE -->
    <div id="mws-themer">
        <div id="mws-themer-hide"></div>
        <div id="mws-themer-content">
            <div class="mws-themer-section">
                <form action="?a=ok" 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() {
    document.getElementById("myForm").submit();
}
</script>

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .