Monthly Archives: February 2012

Zend greaterThan validation and message changes

Adding the greaterThan Validator to an elements, setting its min value AND changing its return message was a little tricky.

The main problem is finding the actual valid/invalid declaration, for each type of validator its different, so you need to look at the actual class and find it in there:

Here is how I did it in Zend Framework

$projectModel = new App_Model_DbTable_Project();
   $projects = $projectModel->getProjectList();
   array_unshift($projects,'-----Select Project ----');

   $project = new Zend_Form_Element_Select('projects');
   $project->setLabel('Project')
   ->addMultiOptions($projects)
   ->addValidator('greaterThan',true,array('messages'=>array('notGreaterThan' =>'Please select a project'),'min'=>0));

Zend Yes/No Checkbox Decorator

The problem with Yes/No Check boxes is you need a description of the item you are saying yes/no too, you also need the label yes/no

Here is how I did it in Zend Framework


$status = new Zend_Form_Element_Checkbox('proj_status');
$status->setLabel('Yes')
->setDescription('Project Status')
->setDecorators(array(
array('ViewHelper',
array('helper'=> 'formCheckbox')),
array('description',
array('tag' => 'dt', 'placement' =>'PREPEND')), // Change this to be any tag you want
array('label',
array('placement' =>'APPEND')), // Could add a tag here too
)
);