viernes, 30 de abril de 2010

Accesibilidad Web

If you are worried about web accessibility in your web page I'm going to give you some guidelines to solve the most common accessibility problems. First of all, you have to know what mistakes you have made. You can figure it out using this web page:

http://www.tawdis.net

Once you know the mistakes in your web page we can pass to try to solve them. You'll be able to resolve some problems using this.

1) A form could be somethin like that:

<form>
First name:
<input type="text" name="firstname" />
<br />

Last name:
<input type="text" name="lastname" />
</form>


If we want the form to be accessible we must to change it like this:

<form>
<label for="firstname">First name:
<input id="firstname" type="text" name="firstname" />
</label>
<br />
<label for="lastname"> Last name:
<input id="lastname" type="text" name="lastname" />
</label>
</form>


2) In order to create a button that send us to the previous page, we would do:

<a href="javascript:history.go(-1)">

But if we want this to be accessible we would have to change it like this:

<a href="<?=$_SERVER['HTTP_REFERER']?>" id='atras'> Atras </a>

<script type='text/javsacript'>
//<![CDATA[
document.getElementById('atras').onclick = function(){
history.go(-1);
return false;
}
//]]>
</script>

jueves, 15 de abril de 2010

Preformatted array variables in PHP

If you want to print an array in PHP you can use this:

print_r($var);

but if you do it like this, if there is much information you can go mad. If you add the tag <pre> the text will apperar preformatted.

echo "<pre>";
print_r($var);
echo "</pre>";

I hope this help you.

Greetings.

viernes, 9 de abril de 2010

Blogger: HTML code without interpreting it

Today I have had some problems with Blogger. I was trying to introduce a HTML code for showinf you, but Blogger caught it and interpreted it.

For solving this there is a web page that can help you. This web page is Simplecode and there you can introduce the code you want to put in Blogger and in the box below it will appear the code you have to introduce inBlogger for showing the code you want correctly.

I hope, this help you.

Javascript function in CakePHP from a controller's function

Sometimes, in CakePHP I've needed to use a javascript function whose code was the code from a function I had created previously in one of my controller. Specifically when I wanted to show a list of users with a link for each user to modify their profile in a "flash element" of CakePHP. Therefore, and as I find it very useful, I'm going to specify the steps to do this.

1 .- Having created the function we'll use in the controller. For example:

function modifica_alumno($id_alumno){
...
}

2 .- We use for example, scroll.js (we could use any javascript file but in this case I've chosen this), in folder app / webroot / js, we edit it and introduce something like:

function perfil_alumno(id_alumno){
var aDIV = "left-center";
var aURL = "/alumnos/modifica_alumno/"+id_alumno;
new Ajax.Updater(aDIV,aURL, {method:'post', asynchronous:true, evalScripts:true});
}


3 .- In another controller's function we refer to the JavaScript function we've just created and display the results by a "flash."

function buscar_alumno($nombre){

...

foreach($consulta as $sol){

$listado .='<a style="text-decoration:none; color:green;" href="#" onclick="perfil_alumno('.$id_alumno.');return false;"> - '.$alumno['nombre'].' '.$alumno['apellido1'].' '.$alumno['apellido2'].'</a><br/><br/>';

}
$this->flash($listado,'index');

}

Here we choose where we want the function to be load in the div, we refer to the controller's function we want to use and ready.

Greetings!!