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
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, privacy policy and cookie policy