php - Zend Framework - integer validator -


zend framework seems have feature validating integers (checked /validate/int.php in library purpose) validates correctly float numbers integer, while want show error when float number given.

here snippet form:

  $form['my_int'] = new zend_form_element_text('my_int');   $form['my_int']->setlabel('my int')                  ->setrequired(true)                  ->addfilter('stringtrim')                  ->adddecorator('errors', array('placement'=>'prepend',                                                  'class'=>'my-err'))                  ->addvalidator('notempty', true, array('messages' =>                       array('isempty' => 'please provide data')))                  ->addvalidator('int', true, array(                      'locale' => 'en_us',                       'messages' => array(                           'intinvalid' => 'please provide valid data',                           'notint' => 'please provide valid data'                      )                  )); 

so when provide different string, integer or float, 'intinvalid' error triggered , custom message shown. when float number 1.23 provided 'notint' error shown. problem when provide e.g. 1.00, validator checks "!zend_locale_format::isinteger($value, array('locale' => $this->_locale))" , decides input integer , when try add float number in the database in integer field, error.

how should organize form validation when float number provided, no matter what, show error user?

you should add int filter element.

$element->addfilter(new zend_filter_int()); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -