[development] How to validate a $node?
robrechtj+drupal at gmail.com
Wed Jun 7 12:43:07 UTC 2006
On 6/7/06, Jim Riggs <drupal-lists at jimandlissa.com> wrote:
> On 7 Jun, 2006, at 3:24, Robrecht Jacques wrote:
> No, I don't set the required taxonomy, but it will be set if
> required. The user has to set it. They are presented with a
> complete node/add form, including taxonomy selection. It's just that
> in my case they can import many items via the body textarea.
Ah, ok. Only read through the code quickly. So the node/add form already
does this validation for you and you don't need to do that validation again.
Then indeed a simple "node_validate()" will work.
But in my case there is no node/add form that the user submitted but still i
want this form validation to be done somehow.
> You also bail out creating quotes from the first error you
> > encounter while I would like to import the next rows too.
> Yeah. That was just a design decision, though. I could have easily
> continued the import.
You check form_get_errors(). If this returns something, you know the
node_valiate() has failed. But how do you clear out the errors you've
already got before the next node_validate() you do in the foreach loop? The
errors stay inside a static array in form_set_error() and can not be cleared
at all. So the import you try after one with errors will also have some
form_get_errors()... in fact, the same ones as the first row with errors.
Your code works, but unfortunately I can't use it as I need to do the "user
presses submit on the node/add form" programmatically too.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the development