I'm receiving by $_POST
I'd like to know if it's wrong to validate if
like this.
$romaneio = filter_input(INPUT_POST, 'romaneio');
if($romaneio == ''){
$romaneio = 'null';
}
I'm receiving by $_POST
I'd like to know if it's wrong to validate if
like this.
$romaneio = filter_input(INPUT_POST, 'romaneio');
if($romaneio == ''){
$romaneio = 'null';
}
There is nothing wrong with your condition, which is interesting to note is as follows, PHP
already considers a condition as false
in the following cases:
Whereas you make the following assignment:
$romaneio = filter_input(INPUT_POST, 'romaneio');
You can simply put your variable in a condition and use it normally if it is not considered false
:
if($romaneio){ //simples assim, sem precisar de comparação
//e no bloco você a utiliza como quiser
} else { //else opcional caso queira setar algo como no exemplo da pergunta
$romaneio = 'null';
}
Or even as you put the question, but simply "denying" the condition:
if(!$romaneio){
$romaneio = 'null';
}
The filter_input
, in addition to bringing the result, also validates the field, bringing FALSE
. I recommend doing:
if (!filter_input(INPUT_POST, 'romaneio')) {
$romaneio = 'null';
}