0

In a custom moudule I find email addresses and return them as clickable mailto anchors on the page.

    $tableEntry['Email'] = l($emailAddress ,'mailto:'.$emailAddress , array('html' => TRUE)); 

    //Snippet of render array being used to create the table.. In a different function from the line above
    $rows = array();
    foreach ($tableEntries as $entry) {
    $rows[] = array(
        array('data' => $entry['Email']), //l($entry['Email'], 'mailto:'.$entry['Email'], array('absolute' => TRUE))),
    );

If i create the anchors before passing them into the table's render array, Drupal does something to strip away the html. I have tried a whole bunch of argument options in l() and have also tried directly entering in HTML into l(), all the time the results get stripped. (I always check the generated email address to be sure it was first created successfully) . The only way i am able to get an anchor to display as a link within the browser, instead of plain text, is to call the l() function at the last step of building the table render array eg. the commented out code. Any explanations are much appreciated.

  • 1
    print l('in@incepti.op', 'mailto:in@incepti.op'); prints the mailto: link perfectly. I think it has to do something with your table. May be posting the table theme part will help. Any call to check_plain() or t() without proper modifiers will ruin the party. – AyeshK Apr 11 '14 at 16:41
2

Just for sanity's sake...from a 'Drupal' point of view, your code works fine. For example (without the loop),

$emailAddress = 'test@test.com';
$entry['Email'] = l($emailAddress ,'mailto:'.$emailAddress , array('html' => TRUE)); 

//Snippet of render array being used to create the table 
$rows = array();
$rows[] = array(
    array('data' => $entry['Email']),
);

print theme('table', array('rows' => $rows));

Produces:

<table>
  <tbody>
    <tr class="odd">
      <td><a href="mailto:test@test.com">test@test.com</a></td>
    </tr>
  </tbody>
</table>

You may have a custom implementation of theme_table() somewhere which sanitises the incoming cell data, but it's not being caused by Drupal core.

Or, it might simply be that you're trying to re-use $entry when it doesn't make sense to.

$entry['Email'] = l($emailAddress ,'mailto:'.$emailAddress , array('html' => TRUE)); 

...

foreach ($tableEntries as $entry) {

Are you sure you meant to overwrite the outer $entry array with the one in the foreach?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.