Last updated June 14, 2010. Created by phayes on September 28, 2009.
Edited by LeeHunter, dkinzer, ahmedz. Log in to edit this page.

This module allows you to fill title, body, and CCK fields from the URL. It auto-populates a field with a value from the URL.

http://drupal.org/project/urlfill

Supported Fields

It supports both single and multi-value fields. It has support for the following field types:

  • Node Title
  • Node Body
  • Textfields
  • Number fields (Float, Integer, Decimal)
  • Node Reference
  • User Reference
  • Content Taxonomy

Setting up fields to be auto-filled

For each field you want to be able to auto-fill, you must configure in the node or field configuration pages.

  • Node configuration can be found at Administer->Content Types->edit
  • CCK Field configuration can be found at Administer->Content Types->Manage Fields->Configure

Here you may set-up the variable from the URL you wish to get data from, and configure other options. For cck fields, the variable defaults to field_yourfieldname, for node title and body fields, it defaults to title and body respectively.

A note about multi-value CCK fields
If your cck field is allowed to have more than one value, then to properly fill from the URL you will need to append [] to the end of the url variable. For example:

  • field_yourfieldname becomes field_yourfieldname[]
  • custom_variable becomes custom_variable[]

Auto-filling

Once you have set-up your fields, you may navigate to a node editing or node creation form and auto-fill those fields by adding extra pieces to the URL.

For example:

www.example.com/node/add/page&title=What a Great Page&body=What a Great Body
www.example.com/node/add/page&field_myfield=Value for my custom Text Field
www.example.com/node/add/page&mymultivalue[]=First Value&mymultivalue[]=Second Value

Some notes about select, radio buttons, etc.
When auto-filling for select fields, radio buttons etc, you need to use the database value, not the exposed user value. For example, if your allowed values look like this:

deer|A Happy deer
moose|An Inquisitive Moose
dragon|An Angry Dragon

Your URL values need to make use of the left-hand side values ('deer','moose', or 'dragon'). You should have no spaces between the values and the | . For example:

A single-value select field:
www.example.com/node/add/page&field_animal=dragon

A multi-value checkbox field:
www.example.com/node/add/page&field_animal[]=dragon&field_animal[]=moose

Some notes about field refereces
To auto-fill a URL for a node-reference, you need to know the nid of the node you wish to reference. Here is a little PHP script to help you do that.

<?php
if (arg(0) == 'node' && is_numeric(arg(1))) {
 
$nid = arg(1);
  print
"<a href='/node/add/page&field_myfield=$nid'>Reference this node to a new one<a/>";
}
?>

Adding support for a new field type / widget

Please submit as patches support for new field types / widgets. Adding support for a new field-type / widget is really very simple. Open-up urlfill.module and locate the function urlfill_get_path. Given a widget, this function maps where in the form to fill in the value. For example node-reference-select widget is filled in at: $form[$FIELD']['#default_value'][0]['nid'], so we return the value array('#default_value',0,'nid'). It is important to note that the zero should be expressed as an integer and not as a string. Filling in a new value for a new widget is all that is needed to enable support.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.