Not possible, as I explained in a similar post:
PHP is usually server-side and in the case of websites, it is always server-side, or PHP generates HTML sends as a response via internet back to you and then your browser renders the HTML response on the screen, ie the PHP function has already been processed:
To summarize all web technology will work under the HTTP protocol, which has requests and responses.
Workaround
The alternative solution is to create a POST call with if after the form is sent, example:
<form action="paginadestino.php" name="myForm" id="myForm" method="POST">
<input type="text" name="edtMFIR" id="edtMFIR" value="" class="mws-textinput error">
</form>
And in paginadestino.php (which can be a . php or just a dynamic page with querystring ?foo=baz
) add the IF:
<?php
if (!empty($_POST['edtMFIR'])) {
myFunction();
}
If you wish to don’t change pages only using Ajax (which changes the whole approach), for example:
<form action="paginadestino.php" name="myForm" id="myForm" method="POST">
<input type="text" name="edtMFIR" id="edtMFIR" value="" class="mws-textinput error">
</form>
<script>
(function () {
var form = document.getElementById("myForm");
form.addEventListener("submit", function (e) {
e.preventDefault();
var oReq = new XMLHttpRequest();
oReq.open(this.method, this.url, true);
oReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//Função assíncrona que aguarda a resposta
oReq.onreadystatechange = function()
{
if (oReq.readyState === 4) {
if (oReq.status => 200 && oReq < 300) {
alert(oReq.responseText); //Pega a resposta do servidor
} else {
alert(oReq.status); //Pega o código de erro da resposta do lado do servidor
}
}
};
oReq.send(new FormData(this)); //Envia os campos do formulário
});
})();
</script>
And in PHP it will also have to be:
<?php
if (!empty($_POST['edtMFIR'])) {
myFunction();
}
So within the "Ifs" you can do whatever you want with Javascript, just adjust:
if (oReq.status => 200 && oReq < 300) {
//Faz algo com JavaScript se a resposta HTTP for "OK"
} else {
//Faz algo com JavaScript se tiver ocorrido algum erro
}
It is not possible. PHP is a server-side language, what you are trying to do you will get with Javascript for example, which acts on the client side, ie in the view/page that is presented to the user.
– Leandro Lima