Simple and basic question

When a form input is submitted with not value in how does it passes?

empty()
NULL()
or
isset()

I have been looking for an answer for a while decided to come here for an opinion.

Form field are passed through $_POST.
By definition $_POST only contains strings (or arrays of strings).
Thus, a field that has not been filled in results in an empty string.
In other words, you should use empty() :slight_smile:

PS. Or $_POST[‘somefield’] == ‘’, or even better trim($_POST[‘somefield’]) == ‘’, so users can not fill in just a space.
PPS. Note that the PHP Manual states that empty(trim($_POST[‘somefield’])) will not work

i was trying this version and it was not working

empty(trim($_POST['somefield']))

then i tried with the operator =

$_POST['name']) =''

But the operator == is what I needed. I thought = was comparing the post index ‘name’ to the empty string, but not now I know that == is used instead of == in this case.

Thank you now it is working.

This checklist/grid getting a bit aged now, but you could study this very carefully as well as the man pages about the order in which PHP tries to make sense of variables.

http://www.deformedweb.co.uk/php_variable_tests.php

It may also lead you to make a lot of use of var_dump() for the sake of your sanity especially when forking code based on conditions. if, else etc

Be aware that empty() returns true for string ‘0’

Alternative is to compare to empty string like
$foo != ‘’
or use strlen()

Thank you for the table.

i have look for the result below in the part of the arrays in the table and I have found it.

(
[0] =>
)

that’s a print_r I have done in one of the index to see how is returning. I believe is false, but any way just want to make sure.

I think you’re getting to the point where you need to start learning more about types. http://www.php.net/manual/en/language.types.php

I wish I had a better link for you, but I don’t. Maybe someone else knows of one that requires less perquisite knowledge, because this part of the manual seems to assume a bit of knowledge of other programming languages. Still, you can learn something from it.

btw- var_dump() gives a more detailed view of a value than print_r() does. In particular, it tells you the type of data it’s printing(and to print/echo, php converts the data to a string which hopefully provides a useful representation of the data).