result confirm to PHP

0

Hello, I'm having the following problem.

In a PHP file I have ...

echo($strconfirm ="<script>confirm('Registro repetido!!!');</script>");
if ($strconfirm == true){
echo "Selecciono si";
}else{
echo "Selecciono NO";
}

But it does not save true or false .

I just want to save the value of confirm in a variable to evaluate it with if .

Greetings

    
asked by mazhivo 12.05.2017 в 21:26
source

1 answer

0

All the interaction with the user that you are trying to develop is developed only on the client's side, in your browser, using a programming language different from PHP, which is executed only once on the server.

You must understand that the server generates an HTML page using the PHP programming language and that the HTML is interpreted (after it has been generated and sent to the client) in a browser and it will not be related to the server until the user returns to click on a link or send a form (or use some XHR asynchronous function).

Everything on the client side

resultado = confirm('Registro repetido!!!');
if (resultado == true) {
  document.write("Selecciono SI");
} else {
  document.write("Selecciono NO");
}

You will see that everything works in local, without the need of a PHP server that receives the answer.

Sending the response via a form to a PHP

resultado = confirm('Registro repetido!!!');
document.formu.resultado.value = resultado;
document.formu.submit();
<form action="receptor.php" method="post" name="formu">
<input type="hidden" name="resultado"/>
</form>

In this case, when you reply you try to send the form to receptor.php , and since it does not exist on the stackoverflow server it sends you an error, but if you run it on your server and have that PHP script, you will receive the result in it.

    
answered by 12.05.2017 в 21:37