How to get the value of a field on the same page

2

I have a form field on a page called cadastro.php, for example. So I want to create a variable that receives the value that the user types in this field, but I want this variable to be in the same code and not on another page, but I do not know how to get this value, since it is not being passed either via post or via get How?

Type I know it's not like this, but I'll put this example to anyone who wants to respond.

field: <input type="text" name="nome"/>

I want to extract to a variable that will be on the same code page as the value that the user types ...

$nome = $_GET['nome']; . I know it's not like that, but how do I do it? Or is there no way?

    
asked by anonymous 04.10.2017 / 21:26

1 answer

2

It would be enough to use% void% and do as follows:

<?php
if (isset($_GET['nome'])) {
    $nome = $_GET['nome'];

    echo 'Olá', htmlentities($nome), '!';
}
?>
<form method="get" action="">
Nome: <input type="text" name="nome">
<button>Enviar</button>
</form>

In this way the request goes to the "same" page that you send the form.

But of course this will do paging , even if it was POST, if you want to update a variable without a page, there is no way, since Web is HTTP and HTTP works like this: p>

That is, you will always have to have a request and answer, however you can use Ajax and maybe combine with session, it depends a lot on what you actually want to do.

    
04.10.2017 / 21:37