Run javascript after PHP

Asked

Viewed 575 times

1

I’m trying to run a PHP function after the page’s Ubmit, but I haven’t been succeeding. Could someone help me?

    <?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();
        }
    ?>

1 answer

1


Your button of submit is out of the form, to store place it inside the tag form, if this affects anything in your layout, submit through the example javascript...

<!--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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.