0
You can tell me how to finish this project, with this code below I managed to define the message that will appear from the number entered by the user given by the administrator
<form action="submit.php" method="post" >
<nav class="zz z_meio2 borda ">
insira o código especifico ou deixe em branco para resposta padrão
<br>
<input type="text" name="CODNOME"><br>
<button type="submit" >Enviar</button>
</nav>
</form>
the code I’m using in Submit.php
<?php
//função para gerar respostas
echo $CODNOME;
if($_POST['CODNOME'] == "001"){
$msg = "mensagem1";
}
else if($_POST['CODNOME'] == "002"){
$msg = "mensagem2";
}
else {
$msg = "opção fixa";
}
echo $msg;
?>
the above code redirects to another page.
But I would like that if the user enters an invalid code or does not enter anything he prints the "msg fixed" printing it without changing page by clicking on the code below.
<input type="submit" value="Imprimir" class="btn no-print" onClick="window.print()">
<div class="print" STYLE="width:660px;">
<p>msg fixa</p>
</div>
this would be as if the result of Submit.php were user print, on the same page, has some way to do this ?
You can use the
action
for the same page as the form. You can type the page name or use$_SERVER["PHP_SELF"]
. Then just check if the variable post is not empty,if (!empty($_POST))
and puts the conditions that you want to verify.– lazyFox
@lazyFox worked well by putting in the same page it generates what I want but now it does not apply the function does not recognize the value inserted in the input neither 001 nor 002 da just as 'Else' as apply the 'if (!Empty($_POST))' na ' <input type="text" name="CODNAME"><br> '
– Luccas Cerqueira