On Thu, Jan 21, 2010 at 12:23 PM, Philip G <[email protected]> wrote: > > I don't suppose there's a way to kind of doing a reverse direction of filer > on data for visual output? > Specifically; > Using Zend_Form(), I have Zend_Filter_Digits on a phone number field. This > works well to strip out all non-digits from a person's number. But now when > the person views the form value, or gets an error and sees their entered > data, the number has been stripped. I'd like to be able to either display > what they put in there, or rather filter it to a valid visual representation > of a phone number. It's really Zend_Filter the other direction, like > Zend_UnFilter. lol > --- > Philip > [email protected] > http://www.gpcentre.net/ >
I agree it would be nice in some cases to have partially or totally unfiltered content shown in the web controls. For this particular case, I created a Project_Form_Element_PhoneNumber that inherits from Zend_Form_Element_Text and has a custom view helper to display phone numbers with the desired visual formatting. It works well for me since all the cases I've had to use it for are in the North American numbering plan. It could get stickier if it had to support international phone numbers, though. As a more general solution, what do you think about this? * a Zend_Formatter_Interface that defines a method format() similar to the Zend_Filter_Interface that defines a method filter(); The framework could include several default formatters that handle common data elements such as dates, numbers, phone numbers, etc. Obviously you could write your own if what you needed wasn't provided. * a new property added to Zend_Form_Element_Text to which one may assign a class that implements this new interface; if a formatter was assigned, it would be used by the view helper to format the value attribute of the input element. I don't think chaining would be necessary here, so a simple 1:1 has-a relationship would be fine. * a boolean property _useUnFiltered that, if set to true, would cause the view helper to bypass the formatter and use the raw, unfiltered input for the value of the input element rather than the filtered value. Andrew
