[development] Form API: Is this possible?

eric Farris eafarris at gmail.com
Sun Feb 19 15:25:20 UTC 2006

On 2/18/06, Earl Dunovant <prometheus6 at 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.


More information about the development mailing list