2

I have got a CCK field set up so that unlimited values can be entered upon node creation (number of values: unlimited).

When I try to print values in a node with the following code

if ($node->field_tip != NULL) {
  foreach ((array)$node->field_tip as $tip) {
   print "<div class='tip'>" . $tip['view'] ."</div>";
  }
}

or I print count($node->field_tip), the value is never less than 1, and <div class='tip'></div> is always displayed, even if there aren't values entered in that field.

1
  • What is the question?
    – apaderno
    Mar 22, 2011 at 0:14

1 Answer 1

3

As far as CCK is concerned, there is still a value, it just happens to be blank (most likely an empty string, depending on what type of field you're using). If you modify your code to check the raw value, you should only see output when there is an actual value:

if ($node->field_tip != NULL) {
  foreach ((array)$node->field_tip as $tip) {
    if (!empty($tip['value'])) {
      print "<div class='tip'>" . $tip['view'] ."</div>";
    }
  }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.