Input text returning bool (false)

3

I have this HTML code

<!DOCTYPE html>

<HTML> 
    <HEAD>
     <TITLE>Cadastro</TITLE>
     <meta charset="UTF-8">
     <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
    </HEAD>   
    <BODY>
        <div class="container">
            <form method="POST" class="form-horizontal" action="teste.php">
                <div class="form-group">
                    <label for="pesNome" class="col-sm-2 control-label">Nome</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="pesNome" placeholder="Nome">
                    </div>
                </div>                
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-default">Gravar</button>
                    </div>
                </div>
            </form>
        </div>
    </BODY>
</HTML>

And this PHP code

<!DOCTYPE HTML>
<html>

<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<?php
        $nome=isset($_POST['pesNome']);
        var_dump($nome);
?>
<a href="index.php">voltar</a>
</html>

My intention is for var_dump to return what was typed in the input keyword , but instead returns me the message bool(false) . Can anyone explain me the reason?

    
asked by anonymous 13.12.2017 / 01:23

1 answer

3

The isset is a value Boolean . So you're assigning the variable $nome a Boolean value ( true or false ).

The correct thing is to assign the variable the $ _POST value:

$nome = $_POST['pesNome'];

And then check if the variable has been fed :

if( isset($nome) ){
    // $nome tem algum valor
}else{
    // $nome não tem valor algum
}
    
13.12.2017 / 02:46