• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
img() - html validation error

#1
[eluser]bgougent[/eluser]
since some time I need to add alt tags to my image for a blind user.
When I use the default img() function in the html_helper I always get an error on the missing alt tag.
So I deceided to change the html_helper with my own html_helper file (application/helpers)

This is the code
Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

include_once( BASEPATH . '/helpers/html_helper'.EXT);


function img($src = '', $index_page = FALSE, $alt='')
    {
        if ( ! is_array($src) )
        {
            $src = array('src' => $src, 'alt' => $alt);
        }

        $img = '<img';

        foreach ($src as $k=>$v)
        {

            if ($k == 'src' AND strpos($v, '://') === FALSE)
            {
                $CI =& get_instance();

                if ($index_page === TRUE)
                {
                    $img .= ' src="'.$CI->config->site_url($v).'" ';
                }
                else
                {
                    $img .= ' src="'.$CI->config->slash_item('base_url').$v.'" ';
                }
            }
            else
            {
                $img .= " $k=\"$v\" ";
            }
        }

        $img .= '/>';

        return $img;
    }

I've added a third parameter 'alt'. If nothing is mentioned the alt is set - still empty. If definied I have a correct alt tag. Both are correct for the HTML validator Smile .

#2
[eluser]Johan André[/eluser]
Whats wrong with extending the html-helper?
(name it MY_html_helper.php and place in application/helpers).

#3
[eluser]InsiteFX[/eluser]
Hi,

For one that I can see you need to change this:

Code:
from: Incorrect

$img .= '/>';

To: Correct

$img .= ' />';

This also applys to Input and meta tags.

Enjoy
InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme ¬© 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.