I have an array of html textbox element with name say date_field[]. There could be multiple fields in the form. After submission of the form to check whether at least one of the textbox is not empty, I used –
<?php
if(empty($_POST["date_field"])){
echo "Is empty";
}else{
echo "is not empty";
}
?>
It echoed is not empty no matter whether I fill or I didn’t fill this date_field.
P.S. If I printed the form value using print_r
If I didn’t put value
[followup_date] => Array
(
[0] =>
)
if I put value
[followup_date] => Array
(
[0] => 2012-12--14
)
Any help will be highly appreciated
Your “empty” array contains an empty string:
That’s not an empty array. The only “empty” array is
array().You may want to run it through
array_filter, which removes all elements evaluating tofalse(which also includes"0", be careful).