Auto-fill from URL

Last modified: November 9, 2009 - 04:07

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

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/>";
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.