Hi there, I'm utterly desperate (being a total novice at all things php) and am hoping someone can assist. In brief, I have a submission form. User adds url. Output should then display as an image link with the amazon affiliate code. In my template I have the following (which I used previously, but which doesn't seem to work now for some odd reason):

<?php
$value = $this->value;
$options = $this->params->get('params.open_url', 1) ? ' target="_blank"' : '';
echo JHtml::link('http://' .$value[0]['url'].'?tag=romautjudrai-20', "<img src='".JURI::root()."images/library/amazon.png'>", $options ) ;
?> 

The only thing different is that I am now using Joomla 3, so perhaps that has something to do with it. Cannot think of anything else, and I have run this through 3 different php checkers which all returned no errors. I've also scoured the internet with no resolution. I've been at it for 2 weeks now, and I'm just not getting anywhere. I would be most grateful if someone can assist.

Thanks,
Jude

Member Avatar for diafol

At which line does it fail?
Use some echo commands to determine where it's all going wrong.

I'm not at all sure, given that my knowledge is more than limited. I also have no idea how to use the echo commands mentioned. this is the line that I think is the problem:

echo JHtml::link('http://' .$value[0]['url'].'?tag=romautjudrai-20', "<img src='".JURI::root()."images/library/amazon.png'>", $options ) ;

It's displaying the image, so that part is ok. It's also echoing the link but as a text link next to (after) the image. It's not adding the url as a link to the image. I hope that makes sense. I'm afraid that's the sum total of my non-existent knowledge.

Is the site available for us to view?

Your "Buy Amazon" image link appears to be in tact, the additional text link after appears to be the one missing the affiliate code, if tag=romautjudrai-20 is your affiliate code.

What happens if you put die(); after the line beginning echo JHtml::link
?

I did a Google search on "joomla 3 links not working" and quite a few hits came up, they could be dead ends, but I'm not familiar with Joomla.

Hmmm... I didn't think that perhaps it might be Joomla related. I'll look into that. I'll also give the above a try thank you.

Juust noticed in my previous post - it should just be die();

Don't put "put" :D

Lol, I gathered that but thank you!

I am sifting through various broken links posts, thus far they all seem to relate to menus or simple inserted into content, but I will keep at it.

In the meantime, I tried the or die bit above. on clicking to open the article I get a plain white screen with the buy image in the top left corner. Clicking on the image gives me:

Not Found

The requested URL /www.amazon.com/Still-Running-BookStrand-Publishing-Judah/dp/1606012134/ref=la_B0032ZVHUM_1_3 was not found on this server.
Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny16 with Suhosin-Patch Server at http Port 81

I just tried you previous link and that has too many http:// in it so can you change

echo JHtml::link('http://' .$value[0]['url'].'?tag=romautjudrai-20', "<img src='".JURI::root()."images/library/amazon.png'>", $options ) ;

to

echo JHtml::link($value[0]['url'].'?tag=romautjudrai-20', "<img src='".JURI::root()."images/library/amazon.png'>", $options ) ;

and see what happens when you click the link

Also, just ran linkchecker, and this doesn't pick up at all.

Eisch! What a to do, lol. removing the double http has at last got the image link to work - thank you!! Now my only remaining issue is that the link appears as a text link alongside the image. I've scoured the rest of the file but to my blind eye it seems the only other references are to list... I've pasted the full code below. I really am so very grateful for all the help. I cannot even begin to explain the stress at not being able to solve this. thank you.

<?php

/**

 * Cobalt by MintJoomla

 * a component for Joomla! 1.7 - 2.5 CMS (http://www.joomla.org)

 * Author Website: http://www.mintjoomla.com/

 * @copyright Copyright (C) 2012 MintJoomla (http://www.mintjoomla.com). All rights reserved.

 * @license GNU/GPL http://www.gnu.org/copyleft/gpl.html

 */

defined('_JEXEC') or die;

?>

    <?php
    $value = $this->value;
    $options = $this->params->get('params.open_url', 1) ? ' target="_blank"' : '';
        echo JHtml::link($value[0]['url'].'?tag=romautjudrai-20', "<img src='".JURI::root()."images/library/amazon.png'>", $options ) ;
    ?> 

<?php if(count($value) > 1): ?>

    <<?php echo $this->params->get('params.numeric_list', 0) ? 'ol' : 'ul class="unstyled"';?> >

<?php endif; ?>

    <?php foreach($value as $i => $val):?>

        <?php if(count($value) > 1): ?>

            <li>

        <?php endif; ?>

        <?php

        $url = $val['url'];

        $url_parse = parse_url($url);

        if($this->params->get('params.link_redirect', 0)){

            $url = JURI::root().'index.php?option=com_cobalt&task=field.call&func=_redirect&field_id='.$this->id.'&record_id='.$record->id.'&url='.urlencode($val['url']);

        }

        ?>



        <?php if($this->params->get('params.favicon', 0)):?>

            <img src="http://www.google.com/s2/favicons?domain=<?php echo $url_parse['host'];?>" align="absmiddle" class="url-favicon">

        <?php endif; ?>



        <a href="<?php echo $url; ?>" target="_blank" <?php echo (!$this->params->get('params.index_redirect', 0) ? ' rel="nofollow"' : NULL);?>>

            <?php echo isset($val['label']) != '' ? $val['label'] : $val['url'] ?>

        </a>

        <?php if ($this->params->get('params.snapshot', 1)):?>

            <?php $img = htmlentities(JHtml::image(JURI::root().'components/com_cobalt/fields/url/assets/loading.gif', JText::_('Snapshot'), array('id' => "snapimg{$id}-$i")), ENT_QUOTES)?>



            <img style="cursor: pointer" onclick="setTimeout(function(){jQuery('#snapimg<?php echo $id.'-'.$i;?>').attr('src', 'http://mini.s-shot.ru/1280/<?php echo $this->params->get('params.snapshot_width', 200)?>/jpeg?<?php echo $val['url'];?>')}, 1000)" src="<?php echo JURI::root(true)?>/media/mint/icons/16/document-text-image.png"

                rel="popover" data-original-title="<?php echo JText::_('Snapshot');?>" data-content="<?php echo $img; ?>">



        <?php endif; ?>



        <?php if ($this->params->get('params.qr_code', 0)):?>

            <?php $img = htmlentities(JHtml::image('http://chart.apis.google.com/chart?chs='.$this->params->get('params.qr_width', 60).'x'.$this->params->get('params.qr_width', 60).'&cht=qr&chld=L|0&chl='.$url, JText::_('URL QR'), array( 'class' => 'qr-image',

            'width' => $this->params->get('params.qr_width', 60).'px', 'height' => $this->params->get('params.qr_width', 60).'px', 'align' => 'top')), ENT_QUOTES);?>

            <img style="cursor: pointer" src="<?php echo JURI::root(true)?>/media/mint/icons/16/barcode-2d.png" rel="popover" data-original-title="<?php echo JText::_('URL QR');?>" data-content="<?php echo $img; ?>">

        <?php endif;?>





        <?php if($this->params->get('params.link_redirect', 0) && $this->params->get('params.show_hits', 1)):?>

            <small><?php echo JText::_('CHITS');?> <span class="badge"><?php echo (int)@$val['hits'] ?></span></small>

        <?php endif; ?>



        <?php if($this->params->get('params.filter_enable')):?>

            <?php echo FilterHelper::filterButton('filter_' . $this->id, $val['url'], $this->type_id, ($this->params->get('params.filter_tip') ? JText::sprintf($this->params->get('params.filter_tip'), '<b>' . $this->label . '</b>', '<b>' .$val['url'].'</b>') : NULL), $section, $this->params->get('params.filter_icon', 'funnel-small.png'));?>

        <?php endif;?>





        <?php if(count($value) > 1): ?>

            </li>

        <?php endif; ?>

    <?php endforeach;?>

<?php if(count($value) > 1): ?>

    </<?php echo $this->params->get('params.numeric_list', 0) ? 'ol' : 'ul';?>>

<?php endif; ?>

Cut lines 65-69 out. Save them into a temp file, it may be that they are used in other page types.

That resolved it for me. I cannot thank you enough. I have delayed the launch of this site for two weeks now, trying to resolve one small thing, You guys rock!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.