Is there a way I can pre-populate the contact form with certain data?

Example: A user is viewing a node. They click a link in the node to enquire about it. The contact form is displayed with the node's name entered in the subject field.

Is this possible, and if so, how?
Thanks!

Comments

You can create a new module

You can create a new module which does the trick, implementing hook_form_alter();

Are there any other ways of

Are there any other ways of doing it?
I'm not a module developer and was hoping for something more GUI based, or an existing module that does something similar...

I found a way...

I eventually found the Advanced Contact module. There's no official v5 release, but it seems to work fine as is.

Problem solved!

In Drupal 5 you just add edit[cid]=

I just discovered you can use prepopulate module to select a contact category. For instance, if you have 3 categories for your contact form and want to pass an url to pre-select category 3, just pass ?edit[cid]=3 in your link, e.g. http://yourdomain.com/contact?edit[cid]=3. Nice.

Thanks for that

Prepopulate seems to be better supported, and is available for D6.
I might use it from now on.

Are you sure?

It is not working for me. And looking at the code, I don't see how it could. Do you have a custom contact form set up?

it isn't working for me, too

it isn't working for me, too .. using drupal 6 and the standard contact form

Try v2.x.dev

Sorry about that. I hadn't actually tested it until now, and you're right; it doesn't work on the basic contact form.
However, if you download the 2.x.dev version, you should find that it works as expected...

D5 'solution'

For D5:

Current module version 5.x-1.3.

simple hack to make the contactform work:
Change line 42

  if (isset($node)) {

to
  if (isset($node) || $form_id == 'contact_mail_page') {

Drupal ontwikkeling

I was able to fill other

I was able to fill other fields using edit[cid]; for example, my contact form at /contact

http://example.com/contact?edit[subject]=This will go into the subject line

Prepopulate contact form with content from a view.

This worked for me also.. and I got a dynamic form by using views in Drupal 6. I have multiple users listing multiple products and needed an easy way for an interested person to contact the user about the product they were listing.

I created a page view that has all the fields I wanted and last, a User: contact-user field.

In the contact-user field I had to overwrite the output and use a regular html img tag to show the little mail icon.

and...

Here is the code I inserted into the "output this field as a link " in views:

user/[uid]/contact?edit%5Bsubject%5D=[title]&edit%5Bmessage%5D=[field_02_value]

Explanation:

'user/[uid]/contact' ---> links to an individual users contact form via the [uid] which I added as a field in views.

then "?edit" --- > accesses the contact form itself.

"%5Bsubject%5D" --- > uses prepopulate to specify the subject field in the form. The issues is that views already has its own replacement variables using brackets [], so to get information to pass through views and become accessible to prepopulate you have to use %5B and %5D to output the brackets [].

and then [title]--- > inserts the views field 'title' into the contact form subject field using the views replacement pattern.

"&edit" ---> reaccesses the contact form. (notice '&' instead of '?')

Then "%5Bmessage%5D=" ---> again bypasses the views replacement patterns and is picked up by prepopulate to insert information into the 'message' field in the contact form.

[field_02_value] ---> is a replacement pattern from views for a custom CCK content field. In this case the description of the users product.

With custom CCK fields and custom contact form fields you can put any content into dynamic contact forms using prepopulate.