Custom Zend Validator error messages

The Zend Validator error messages are not the most helpful. Considor the below code for creating a file input:

$this->addElement('file', 'signature', array(
    'validators' => array(
        array('Size', false, 20480), //20k
        array('Extension', false, 'png'),
    'required' => false,
    'label' => 'Signature',
    'destination' => SIG_PATH,

For instance, on the above file input, if you attempt to upload something that is not a PNG file (i.e. photo.JPG, the message will be:

File 'photo.JPG' has a false extension

That’s not very user friendly as it doesn’t give the user any indication of what is an “allowed” file type.

Continue reading

JQuery – bind event to non existant element

We all have to bind events to elements:

    do some stuff

But, what if that element doesn’t exist yet? Well, you can use the “live” handler:

$('#link').live('click', function(){
    do some stuff

This will carry the event handler on and will match any future element that matches the selector.

More information can be found here: http://api.jquery.com/live/