HowTo: Use tokens to pre-fill the contact form

Last modified: March 7, 2009 - 17:20

This 10-step tutorial will assist you in creating custom tokenized links. Such links, in combination with the great Advanced Contact module, will allow you to create links which automatically select a catagory on the contact page, and can even send tokenized subject information.

The end result may look, for instance, like this:
<a href="../contact&catagory=General&subject=Request for information regarding: [title]">Ask for information</a>

Assuming you've created a catagory called "General" for your contact forms, this links will open the contact page with "General" as the catagory and "Request for information regarding: Node-title-will-be-here" as the subject.

So how does this work?

1. Download, enable & configure CCK.module

2. Download & enable Tokenize.module (which requires Token.module). Sep. 04 2008: Note tokenize issues #294940, #273294 and #283480.

3. Download & enable the Advanced Contact.module.

4. Go to admin/content/types and select the desired content type. Then click on the "Add field" tab.

5. Specify a name for the field, select Text > Text Field as the field type and hit the "Create field" button. (The Text module in the CCK modules fieldgroup must be enabled for this field type to be used.)

6. Give your new field a label.

7. Now for the magic - Enter your desired link under "Default value", and set your tokenization method under "Tokenization" (more info about the 2 "on" options is available on the Tokenize.module project page). Set the rest of the options as you desire, and click on "Save field settings".

A few examples of tokenized links:
<a href="../print/[nid]">Print page</a> - This will links to the Print.module version of the node (if available).
<a href="../contact&catagory=Products&subject=A question about: [title]">Print page</a> - Will send the user to the contact page, have the "Products" catagory selected and prefill the subject with "A question about: Title-Of-The-Node".

8. Because of issue #273294, you must now again edit the field, and select the proper default input format. Note that if using the standard formats, you will need to use the "Full HTML" format for the links (as stated above) to function.

9. Set the Display option for the field as you wish.

10. Create a new node - A prefilled CCK text field will be displayed. If you don't change anything in it, when submiting the form the field will display the proper links.

Simple, fun & Highly effective.

Enjoy.

 
 

Drupal is a registered trademark of Dries Buytaert.