I need to initialize the body field of nodes that are NOT created by my module, taking a piece of the query string to look up the value to use. With version 4.6, I would set the value of $node->body using hook_nodeapi(), $op='form pre'. With version 4.7, I'm initializing the $node->body using hook_nodeapi(), $op='prepare'. If I dump the $form_values array that is passed to hook_alter(), I find $form['#node']['body'] and $form['body_filter']['body']['#default_filter'] contain the value I assign in hook_nodeapi() but the field form doesn't use the value. Is there a nice, straigtforward explanation of how to prefill a form field?
On 2/18/06, Earl Dunovant <prometheus6@gmail.com> wrote:
I need to initialize the body field of nodes that are NOT created by my module, taking a piece of the query string to look up the value to use.
With version 4.6, I would set the value of $node->body using hook_nodeapi(), $op='form pre'. With version 4.7, I'm initializing the $node->body using hook_nodeapi(), $op='prepare'. If I dump the $form_values array that is passed to hook_alter(), I find $form['#node']['body'] and $form['body_filter']['body']['#default_filter'] contain the value I assign in hook_nodeapi() but the field form doesn't use the value.
Is there a nice, straigtforward explanation of how to prefill a form field?
node.module still contains code (in node_add()) to pre-fill body, teaser, and title from $_GET, so you could craft a url with a query string like ?edit[body]=node%20body%20goes%20here or similar. This is what freelinking.module does, to create nodes with titles passed on the url. I submitted a patch (http://drupal.org/node/27155) to prefill the entire $node object, but with the forms api it was decided that it would be better to manipulate the $form array rather than $node. There is a rest.module, existing solely as a proof-of-concept, that does this using hook_form_alter. That's setting via $_GET. While not exactly what you're after, maybe you could use something similar. -- e www.eafarris.com
On 2/19/06, eric Farris <eafarris@gmail.com> wrote:
I submitted a patch (http://drupal.org/node/27155) to prefill the entire $node object, but with the forms api it was decided that it would be better to manipulate the $form array rather than $node. There is a rest.module, existing solely as a proof-of-concept, that does this using hook_form_alter.
whoops. Should have mentioned that the rest.module I'm speaking of is in my sandbox: http://cvs.drupal.org/viewcvs/drupal/contributions/sandbox/eafarris/rest/ -- e www.eafarris.com
Thanks for the help. It turns out that after getting some sleep, setting field values in hook_nodeapi(), $op='prepare' works fine. I have no idea what I was looking at. On 2/19/06, eric Farris <eafarris@gmail.com> wrote:
On 2/19/06, eric Farris <eafarris@gmail.com> wrote:
I submitted a patch (http://drupal.org/node/27155) to prefill the entire $node object, but with the forms api it was decided that it would be better to manipulate the $form array rather than $node. There is a rest.module, existing solely as a proof-of-concept, that does this using hook_form_alter.
whoops. Should have mentioned that the rest.module I'm speaking of is in my sandbox:
http://cvs.drupal.org/viewcvs/drupal/contributions/sandbox/eafarris/rest/
-- e www.eafarris.com
On Sun, 19 Feb 2006 16:26:41 +0100, eric Farris <eafarris@gmail.com> wrote:
On 2/19/06, eric Farris <eafarris@gmail.com> wrote:
I submitted a patch (http://drupal.org/node/27155) to prefill the entire $node object, but with the forms api it was decided that it would be better to manipulate the $form array rather than $node. There is a rest.module, existing solely as a proof-of-concept, that does this using hook_form_alter.
whoops. Should have mentioned that the rest.module I'm speaking of is in my sandbox:
http://cvs.drupal.org/viewcvs/drupal/contributions/sandbox/eafarris/rest/
And it should be noted that I told you that this module is indeed only a proof of concept as the typical recursive form tree walker is needed -- and I won't include that in form_builder because most of the time it is not needed but the value decider code is complex enough already.
participants (3)
-
Earl Dunovant -
eric Farris -
Karoly Negyesi