Hi,

The problem is with #link form field. I have to insert image tag inside anchor tag instead of title but I am not finding how could I add this. Now link is coming with title Delete. Following is my code :

// Delete link for deleting the node.
'link-delete' => array(
  '#type' => 'link',
  '#title' => t('Delete'),
  '#href' => 'admin/test/delete/',
  '#options' => array(
     'attributes' => array('class' => 'delete'),
     )
),

In this code in place of t('Delete'), I want some image i.e <img> tag inside <a> tag . Please suggest me solution for this.

Comments

Where are you trying to do

Where are you trying to do this? In which hook / template / preprocess function / ... are you putting this?

Thanks for your reply!

I have created a custom form that showing listing of nodes with a DELETE link with every node from a custom table. Everything is working fine with this form, it is also deleting specific record from table when I click on DELETE link but the problem is related to UI/theme of this link. Basically I have to show this DELETE link as an image without using css.

Right now this delete link source code is :
<a id="edit-test-257-link-delete" class="delete" href="/test/delete/1">Delete</a>

Required UI is :
<a id="edit-test-257-link-delete" class="delete" href="/test/delete/1"><img id="delete-icon" src="delete.png"></a>

Just need to use image for link (inside anchor tag) not title. Want following tag inside anchor tag

<img id="delete-icon" src="delete.png">

I hope now it is clear to you.

Pushpinder Rana

.

So that code example is from the Form API. Looks different than what I'm used to, which is why I asked ;) Something like this should do the trick:

// Delete link for deleting the node.
$alt = t('Delete');
$link = l("<img id='delete-icon' src='delete.png' alt='$alt' />", 'admin/test/delete/', array('attributes' => array('class' => 'delete'), 'html' => TRUE));
$form['link-delete'] => array(
  '#type' => 'item',
  '#value' => $link,
     );

Edit: Forgot to add the parameters to l() to process the HTML. Added now.

<?php'link-delete' => array( 

<?php
'link-delete' => array(
 
'#type' => 'link',
 
'#title' => '<img id="delete-icon" src="' . file_create_url('path/to/delete.png') . '" alt="' . t('Delete') . '" title="' . t('Delete') . '" />',
 
'#href' => 'admin/test/delete/',
 
'#options' => array(
   
'attributes' => array('class' => 'delete'),
   
// Need to add this otherwise the image tag is
    // printed to the browser, rather than the image the
    // tag represents:
   
'html' => TRUE,
  )
),
?>

Jaypan We build websites

Thanks a lot Jaypan!

Hi Jaypan,

I am truly grateful to you for this. This worked for me, this is exactly what I want.

Thank you, thank you, thank you!

Pushpinder Rana

nobody click here