views:

61

answers:

1

I'm trying to validate a set of nodes before saving them to the database:

foreach ($nodes_to_save as $node) {
    if (! (node_validate($node, $form))) {
        form_set_error('', t('Node %title did not validate. No nodes were saved.', array('%title' => $node->title)));
        $success = FALSE;
        break;
    }
}

The documentation for node_validate says that it will call form_set_error() to indicate why the node hasn't validated. However, this does not happen with the above code. All I get is the error I set manually. What am I doing wrong?

A: 

try this the $form should be an array !

foreach ($nodes_to_save as $node) 
{
    if (! (node_validate($node, $form))) 
    {
        form_set_error('', t('Node %title did not validate. No nodes were saved.', &drupal_static(__FUNCTION__));
        $success = FALSE;
        return $success;
    }
}

Or dont use the if beause node_validate doesnt return true or false;

foreach ($nodes_to_save as $node) 
{
       node_validate($node, $form);
        $success = FALSE;
        return $success;
    }
}

note that node_validate takes as first parameter an object and as second parameter an array

streetparade