Can we make the email form link say something other than "Email Contact form"?

beckyjohnson - November 25, 2008 - 22:16
Project:Email Field
Version:6.x-1.1
Component:User interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Instead of having the link to the email form for this module read Email contact form, can we change it so that we can put in our own custom text? On my site I want to use the names and job title of the person whose email it is for the link.

Is this possible?

Thanks,
Becky

#1

malc_b - April 19, 2009 - 19:16

String override module will change the strings, the cck field title and the contact form page title too (SO is case sensitive). I don't think you can change the contact form to say Contact Mr Big as the token wouldn't be available on that page. Might work on the cck field page though.

#2

beckyjohnson - April 20, 2009 - 16:48

Thanks for the tip. I think it's ok if the contact form doesn't have the Contact Mr. Big on it, just as long as the link going to it does say his name..

Thanks,
I will play around with this.

Becky

#3

malc_b - April 21, 2009 - 09:29

Add contact Mr Big is tricky. The work around I have is to code the link separately. If you enable the email form then the rendered page gets a link like /email/4/field_contact where 4 is $node->nid and field_contact is the name you gave the contact email field. So if you set in display fields to exclude the email form then the automatic link disappears. You can then add in your own button or link with php i.e.

<?php
print '<a href="/email/' . $node->nid . '/field_contact">' . $realname . '</a>';
?>

where $realname is the person's name, perhaps a field.

The only way to get the name on the contact form I think is to insert the form into another node with cck perhaps. Or you could have a custom tpl file page-email.tpl.php in your theme directory. Or add to theme template.php a rewrite function - function mythemename_preprocess_page(&$vars). That can alter all the page variables. I'm not sure which is the faster as you could just rewrite the variables at the start of page-email.tpl.php then include the standard page.tpl.php

#4

jastraat - June 5, 2009 - 15:51

I solved this by adding the following function to my theme's template.php file

function themename_preprocess_page(&$variables) {
  if (arg(0) == 'email' && is_numeric(arg(1))) {
    $node = node_load(arg(1));
    $variables['title'] = 'Email '. $node->title;
  }
}

#5

beckyjohnson - June 5, 2009 - 16:23

Oh! Great. Will this work for D6?

Becky

#6

jastraat - June 5, 2009 - 16:39

Sorry - to clarify, the code above is for Drupal 6. I don't think this exact code will work in Drupal 5 although you might be able to do something similar with the phptemplate variables.

#7

beckyjohnson - June 5, 2009 - 17:51

Ok, so I put the function in my template and cleared my cache, and edited an old node that had a contact field on it, made with this module. Then I saved it and tested it .... nothing happened on the contact form.... is there some other setting to change?

Becky

#8

jastraat - June 5, 2009 - 20:48

Just to check - did you replace 'themename' with the name of your theme?

#9

beckyjohnson - June 5, 2009 - 22:06

Oh! No . I didn't even notice that. Thank you. I'll fix it.

Becky

#10

beckyjohnson - June 5, 2009 - 23:26

Ok! It totally works now. Is there a way to use some other variable so that instead of printing out the node title, you could get it to print out the email address the form would be going to?

Thanks,
Becky

#11

jastraat - June 7, 2009 - 23:33

Sure - the $node object should contain all the fields related to that node, including the email address field. To find the field name to call, you could use the devel module to find the values or use print_r() temporarily to print out the contents of the node object.

One word of caution though - if you print out the email address in the title, you're exposing that email address to spam harvesters and negate most of the point of using a contact form.

#12

beckyjohnson - June 8, 2009 - 00:06

Thanks, that's good to know. You are right about the spam harvesters. I think what I"ll do is just print out the company name, in my case, that is associated with the email. I wish I could print out the name of the person that email belongs to, but the email module doesn't seem to provide for a name to be associated with an address..

Becky

#13

pamreed - July 1, 2009 - 19:20

Hi
Thanks for this great posting it was great help.

Here is another option for #3 which does not use php. The code can go right in the view in the email fields 'Rewrite the output of this field'. Like this

<a href="/email/[nid]/field_email" class="contact_form">[title] Contact Form</a>

You have make sure you inlclude the node nid as one of you fields and just check exclude from display. The title has my user name.

Also, has a note if you already of a the themename_preprocess_page function in your template.php you can just add the code into it.

Again, thanks worked great.

Pam

 
 

Drupal is a registered trademark of Dries Buytaert.