[development] Stupid forms/node API question
Syscrusher
scott at 4th.com
Sun Dec 11 05:38:29 UTC 2005
On Saturday 10 December 2005 18:24, Karoly Negyesi wrote:
> On Sat, 10 Dec 2005 23:18:11 +0100, Syscrusher <scott at 4th.com> wrote:
>
> First. The subject is wrong, there are no stupid questions. We all learn.
Kindly and wisely spoken. Thanks. :-)
> > I've been all over the code, but I can't seem to find where that's
> > happening.
> >
> > Can someone help? Thanks!
>
> Well, the actual value is calculated from $_POST['edit'] values and
> #default_value . If there is a _POST value, then it overwrites the
> #default_value .
I accept and believe what you're saying. For the sake of my greater
understanding, though, can you point me to the specific module and
function to look at, so I can see it in the code? Again, I do believe
you...but I want to seize the "learning moment", as it were. :-) I did
a search on "POST" in node.module and form.inc, but wasn't sure which
of the occurrences was "the one" where the anomaly happened.
Nota bene #1: The existing documentation on the forms API is
*terrific*. The existing documentation on the node API is *wonderful*.
However...there seems to be a bit of a gap talking about how they integrate
with one another, that is, how the node API uses the forms API, and what
functions in what order for typical node ops. I realize all of this is new,
but I'd love to see (when time permits) a brief overview of that aspect.
Nota bene #2: Here's my contribution of a tip, which I *think* isn't in
the docs yet, but maybe I just overlooked. I was wondering why there are
both node_invoke() and node_invoke_nodeapi() functions that appear to
do almost the same thing...and in fact are called right in sequence from
most of the node.module places that use them. I thought one of them might
be a deprecated form, for legacy modules, and was wondering which was the
preferred approach. But after examining the node.module code (yeah for
Open Source!!!!), I found that they do serve different functions:
* node_invoke()
+ Only invokes hooks for the node handling module of the current type
+ Invokes the hooks of the form $type_$hook() where $type is "story",
"page", etc., and $hook is "load", "delete", "form", etc.
* node_invoke_nodeapi()
+ Invokes the hook_nodeapi() implementation in all functions that
have defined it.
+ Invokes $type_nodeapi(&$node, $op, ...etc....) where $op is the
semantic equivalent of $hook from node_invoke()
I may have just overlooked this differentiation in the docs, but I didn't
see it this explicitly stated. When I finally figured it out, it was a
real "slap on the forehead" moment for me. :-)
If this is in the docs, tell me to shut up and go away, but if not, then
I'll be glad to write something up as a doc contrib if you want.
>
> There are at least two solutions:
>
> a) You change $_POST
> b) You add a #value to the form element in this case. Have you read the
> documentation that you should never use #value? This is the exception.
> However, be extremely cautious what you set here, it'll be sent back to
> the user.
Yes, I saw that documentation that said #value should not be used for
anything the user was allowed to change. Ironically, I originally had
thought about using #value in this situation, then saw that in the docs,
and assumed I shouldn't. :-) I'll give that a try.
I thought of the modification of $_POST, but considered that to be a no-no.
If #value doesn't work, I'll try the other approach.
Many thanks for the response, Karoly! I'll post to the list tomorrow after
I've had a chance to try your suggestions.
Scott
--
-------------------------------------------------------------------------------
Scott Courtney Drupal user name: "syscrusher" http://drupal.org/user/9184
scott at 4th dot com Drupal projects: http://drupal.org/project/user/9184
Sandbox: http://cvs.drupal.org/viewcvs/drupal/contributions/sandbox/syscrusher
More information about the development
mailing list