I want to create custom error messages for fields in a form. In these fields you are required to enter a number range that has to be in between 1 - 999999999999999999999.99, if its below 1 or over 99999 etc. i want a certain message to show.
This is the code i have for the moment but all i am getting is a blank white screen when i try to open the form.
$fee = new Zend_Form_Element_Text('job_salary');
$fee->setLabel("Salary ");
$fee->setAttrib('class', 'input-block-level');
$fee->addDecorator("ViewHelper");
$fee->addValidator('Float');
//$fee->addFilter("Alnum");
$fee->addValidator(new Zend_Validate_JobValidator(), true);
$fee = $salary->getMessageTemplates();
$fee->setMessage(
Zend_Validate_JobValidator::NOT_BETWEEN_SALARY
);
$fee->setRequired(true);
$this->addElement($fee);
This is the function for one of the fields.
I then created a separate validator class rather than using the Zend one.
const MSG_NUMERIC = 'msgNumeric';
const NOT_BETWEEN = 'notBetween';
const NOT_BETWEEN_SALARY = 'notBetween';
const NOT_BETWEEN_STRICT = 'notBetweenStrict';
public $minimum = 1;
public $maximum = 99999999999999999999999999999.99;
protected $_messageVariables = array(
'min' => 'minimum',
'max' => 'maximum'
);
protected $_messageTemplates = array(
self::MSG_NUMERIC => "'%value%' is not numeric",
self::NOT_BETWEEN => "'%value%' is not between '%min%' and '%max%' inclusively - Please fill in the correct amount for fees",
self::NOT_BETWEEN_SALARY => "'%value'is not between '%min%' and '%max%', inclusively - Please fill in the correct amount for this position ",
self::NOT_BETWEEN_STRICT => "'%value%' is not strictly between '%min%' and '%max%' inclusively - Please fill in the fee for this placement"
);
public function isValid($value) {
$this->_setValue($value);
if (!is_numeric($value)) {
$this->_error(self::MSG_NUMERIC);
return false;
}
if ($value < $this->minimum) {
$this->_error(self::NOT_BETWEEN);
return false;
}
if ($value < $this->minimum) {
$this->_error(self::NOT_BETWEEN_SALARY);
return false;
}
if ($value > $this->maximum) {
$this->_error(self::NOT_BETWEEN_STRICT);
return false;
}
return true;
}
}