Search code examples
phpzend-formcurrencyzend-form-element

Zend form element for customized currency


How to extend zend form element to create customized currency field.

For example:

$amount = new Example_Form_Element_Currency(1234);

The out put should be like this: $1,234.00.

I want a custom helper for currency.


Solution

  • Sounds like you're looking to apply a filter.

    I don't think there's a built-in currency filter however it wouldn't be difficult to create one to run the submitted value through number_format() or similar.

    class My_Filter_Currency implements Zend_Filter_Interface
    {
        public function filter($value)
        {
            return '$' . number_format($value, 2);
        }
    }