I'm trying to create a simple Zend form using pm_Form_Simple
class. I need a callback validator with its addElement
method. Here's what I did.
$form = new pm_Form_Simple();
$form->addElement('text','my_number',
array('label'=>'Your number',
'validators'=>array(
array('name'=>'Callback',false,'
options'=>array('messages'=>'Invalid number',
'callback'=>function($value,$context=array()){
if($value < 0){
return false;
}else{
return true;
}
},
))
)));
This gives me an error when submitting the form
Missing argument 1 for CommonPanel_Validate_Callback::__construct()
I have tried this structure also
array(
new \Zend\Validator\Callback(
array(
'messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'Invalid number'),
'callback' => function($value){
if($value < 0){
return false;
}else{
return true;
}
}
)))
This gave me an error include_once(Zend/Validator/Callback.php): failed to open stream: No such file or directory
I don't see Zend/Validator
in my zend installation,so I changed it to zend/Validate
This time the error was Class 'Zend\Validate\Callback' not found
I know there exists LessThan
& GreaterThan
validators, but can anyone kindly help/guide me on how to add callback
validator with addElement
function ?