By bubuk.gabrok on
I have a link within my block that provides a link to Drupal's contact form. I would like my visitors to report anything that they don't like about the site or found some material that should not be put online. Once that link is clicked, would it be possible to fillup the Subject or Message by some default values. I am thinking of filling up the Subject field with the refering URL but don't know how. Appreciate of advice. Thanks.
Comments
prefilled contact form
would be interested in that, too.
best would be if standard arguments to mailto: (subject, body, ...) would be taken from GET when coming to the contact form initially (i.e. w/ empty POST).
I'll try a hack inside contact.module, like if( empty( $_POST ))... but an "official", synchronized approach it would be better....
UPDATE:
The following did it for me : in my version of contact.module I inserted a new line # 448
Then I can make a link href=...contact?subject=welcome+page
and it prefills the subject with this string, which can afterwards be modified in the form.
Hope that helps someone else.
Just what I am looking for.
Just what I am looking for. Thanks alot.
I added the two lines and
I added the two lines and entered the line below on a page to prefill the contact subject (Drupal 5.2).
TESTLINK
< a href="http://XX.XX.XX.XX/xxxxxxxxxxx/?q=contact?subject=testvalue" > TESTLINK< /a >
(without the spaces in the tags)
Unfortunately this does not work (page not found). What else do I have to consider?
Thanks in advance
jeckl
You shouldn't hack drupal core directly
This can lead to problems when upgrading your installation (you would need to add the new line to the contact.module file every time you replaced it with a newer version).
Instead, Drupal provides you with 'hooks' that you can use to tie into the core functionality without editing the core files. In this case, the hook you want is called 'hook_form_alter', and it allows you, unsurprisingly, to alter forms. The function looks like this:
What you want to do is make a module, and add an implementation of hook_form_alter to it. So you create a new directory in sites/all/modules, called, say, 'contact_subject'. Inside that directory make two new files called contact_subject.module and contact_subject.info. Fill out the info file with the name, group, and description of your module (you can copy existing modules for the structure of this file.)
Then, for contact_subject.module, add this code:
The only part of the code that changes is that you use the form_id to tell the hook which form you want to alter. Every time Drupal displays a form, it asks all active modules if they have an implementation of hook_form_alter, and then runs through all of them. In this case, your function just checks to see if the contact form is being displayed, and if a subject is being passed in the URL. If they are, it pre-fills the topic.
(If you don't know the ID of the form you want to alter, you can just activate a dummy module with form_alter printing the ID on every form:
)
With the code split out into its own module, you can update Drupal freely, without overwriting your changes.
How to make the module
Thanks rssaddict! I used your tips to build a module for Drupal 6, which pre-fills the subject and message fields of the contact form.
To build a module which pre-fills the personal contact form with content from a link using $GET, create two files in a folder named 'contact_subject':
contact_subject.info file
contact_subject.module file (note: don't close the php in the end with ?>)
Example link, with info to populate the form with: http://example.com/user/1056/contact?subject=Nodetitle&link=http://examp...
The snippet of code above can
The snippet of code above can be simplified:
I'm looking at doing the
I'm looking at doing the same, I have a variety of email addresses people need to be able to contact and I want to prefill both the message and subject with the same data. Can I do it the same way, or is there an easier way?
Thanks!
Contact Form module
Use the Contact Forms module. You can put your subject in the URL that points to the contact page, and it'll be inserted in the Subject field.
Advanced contact port to D7
This would be the best: http://drupal.org/node/1395288
Unfortunately I'm on other projects and helping on other module patches and ports and I'm collapsed of work.
Hope somebody can help on that ;)
webform
This is an informative thread. @rssaddict I appreciate your breakdown on creating ones own module to hook into a form. Best documentation I have seen for this.
The one thing I have to add to the conversation is that some people that come across this thread might want to consider using the webform module (http://drupal.org/project/webform) as opposed to the contact form. You can create custom forms, pass in information from the url and tokens AND you can display this to the user or hide it and just make it part of the email. (see http://drupal.org/node/296453#webform-user-default)
Anyway, it's certainly worth considering.
A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com
D7 version, implementation in theme
I got the same functionality working under D7, with the following lines in the template.php file of my custom theme:
Thanks for the suggestions!