mediatribe.net -- Drupal et développement web

Notice: this post was last updated Il y a 5 years 11 weeks so it might be outdated. Please be cautious before implementing any of suggestions herein.

Using prepopulate on Drupal 7's contact form

Say I have several categories in my Drupal contact form, and I'd like to create a link to the contact form, but with one of those categories preselected, and, while I'm at, prepopulate the subject and message fields, here's how I go about it.

(1) install and enable the prepopulate module.
(2) Figure out which category (recipient) you want to preselect by finding its ID on the page example.com/admin/structure/contact
(3) Say your message is "this is my message" and your subject is "I'd like some more info & pricing please": pass those two strings in php's urlencode() function.
(4) Put everything in the following format:

<?php

/contact?edit[subject]=SUBJECT&edit[message]=MESSAGE&edit[cid]=CID
?>

If our cid (category ID) is 14, this would give us the following path
<?php
/contact?edit[subject]=I%27d+like+some+more+info+%26+pricing+please&edit[message]=this+is+my+message&edit[cid]=14
?>

Note that if you want several lines on your message, a newline is encoded as %0A (for some reason I can't get urlencode() to generate this for me)