Link on Image with hidden URL link
Hello Friends,
Yesterday I was working on cakephp 1.3.6 based project and come to a point that “How to put an image in your views and also give link on that image. When the user brings mouse pointer on it, he must not be able to see the url. Also make a confirmation alert, once the user clicks on it.
It was a little bit complex at beginning but finally done. I think it may be useful for beginners so I decided to post it here.
The cakephp code.
<?php echo $html->image('mail.png', array('onClick'=>'javascript:confirm(\'Are U sure to notify the user by mail?\')?location.href=\''._ROOT.'/admin/admins/notify_user/?act=notify&uId='.$userid.'\':\'\'','style'=>'cursor:pointer','title'=>'Notify the user by mail?','alt'=>'Notify the user by mail?'));?> |
In other way you want to write the code something like below, use the above code in cakephp.
<img alt="Notify the user by mail?" title="Notify the user by mail?" style="cursor:pointer" onclick="javascript:confirm('Are U sure to notify the user by mail?')?location.href='http://localhost/xyz/admin/admins/notify_user/?act=notify&amp;uId=1':''" src="/ordertracker/Code/img/mail.png"> |
The code is used for admin. Here admins_controller.php is the controller and admins/notify_user.ctp is the view in which this code is written.
I used this code in cakephp1.3.6 (an older version), if someone try to use it in a newer version, please try to write the code if some/any difference is there.