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

Comments

malc_b’s picture

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.

beckyjohnson’s picture

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

malc_b’s picture

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.

 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

jastraat’s picture

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;
  }
}
beckyjohnson’s picture

Oh! Great. Will this work for D6?

Becky

jastraat’s picture

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.

beckyjohnson’s picture

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

jastraat’s picture

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

beckyjohnson’s picture

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

Becky

beckyjohnson’s picture

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

jastraat’s picture

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.

beckyjohnson’s picture

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

pam.pkrweb@gmail.com’s picture

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

flortjes’s picture

Hi,

Absolutely brilliant.

I like the View rewrite approach. Just for anyone reading this thread. Make sure you add the node id field above (!) the e-mail field. Also, make sure the title field is not a link to anything (the token captures such a link). If it is a link, you could just add another (not linked) title field.

Flor

rkendall’s picture

@jastraat #4 - thanks very much for the handy tip, works a treat! :-)

kaido.toomingas’s picture

Can I do some like that for this one.. code from email.module

function email_menu() {
  $items['email/%/%'] = array(
    'title' => 'Email Contact Form',
    'page callback' => 'email_mail_page',
    'page arguments' => array(1, 2),
    'access callback' => 'user_access',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  $items['admin/settings/email'] = array(
    'title' => 'CCK Email Contact Form Settings',
    'description' => 'Administer flood control settings for email contact forms',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('email_admin_settings'),
    'access arguments' => array('administer site configuration'),
  );
  return $items;
}
kaido.toomingas’s picture

Can I do some like that for this one.. code from email.module

function email_menu() {
  $items['email/%/%'] = array(
    'title' => 'Email Contact Form',
    'page callback' => 'email_mail_page',
    'page arguments' => array(1, 2),
    'access callback' => 'user_access',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  $items['admin/settings/email'] = array(
    'title' => 'CCK Email Contact Form Settings',
    'description' => 'Administer flood control settings for email contact forms',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('email_admin_settings'),
    'access arguments' => array('administer site configuration'),
  );
  return $items;
}
kaido.toomingas’s picture

Some for this topic

function theme_email_formatter_contact($element) {
  return !empty($element['#item']['safe']) ? l(t('Email contact form'), 'email/'. $element['#node']->nid .'/'. $element['#field_name']) : '';
}
tnanek’s picture

How about setting it up so that the field's options on the field display configuration screen have an ability to set the text that appears for the link to the contact form.

Just brainstorming here; I may work on a patch if this would be a friendly approach to the maintainers; until something like that is done, the above workarounds are adequate enough.

Also, this specific approach would only apply to the D7 branch, though I'm sure you could add configuration options to the CCK field display configuration screen as well.

brylie’s picture

Version: 6.x-1.1 » 7.x-1.2

I would also like to rewrite the node view of the email field. I think tnanek has a good idea.