[development] How to validate a $node?

Robrecht Jacques robrechtj+drupal at gmail.com
Wed Jun 7 08:29:47 UTC 2006


On 6/7/06, Moshe Weitzman <weitzman at tejasa.com> wrote:
>
> > - how does one validate a node programmatically *correctly*?
> > - what is the point of the "node_validate()" function and the hooks if
> > it doesn't actually *validate* the node at all? At least rename it to
> > "node_noop()" so things are clear.
> > - really, why have "node_validate()" at all? Does anyone do anything
> > usefull in it?
>
> good question.
>
> unfortunately, 4.7 is a bit of an intermediate solution which makes this
> hard. the conceptual way to do is is to programtically "submit" the story
> form. In 4.7, this amounts to populating the proper $_POST variables like
> 'type' and 'title' and so on and then building the node form by calling
> the
> right functions and then calling drupal_get_form(). the node form is the
> most complex of all our forms so i'm not sure this works right.


OK. This is more or less the path I'm following: getting the node-form array
passing it the $node object. This will set the #default_value everywhere.
Then I copy the #default_value values into #value and set #need_validation.
Then I do a drupal_form_validate().

Problem here is: form_set_error() keeps a static variable of the errors on
the form. So if you want to import *two* nodes, the errors of the first run
will still be present in the second run with no way of clearing them.

form api 2.0 will be focused on making things like this easy again.


I'm not critizing form api 1.0. I think it works great in most cases. But
not in mine :-(
Seperating data (with validation / submit) and the actual form seems like
the way forward.

 Robrecht
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20060607/f87ea076/attachment.htm


More information about the development mailing list