Nevermind. It appears -- emphasis on "appears" -- that attaching the filter
to the element before attaching the element to the form does not work. What
does appear to work is adding the element to the form, then adding the
validator to the form element.

Please do tell me if I'm wrong.



On Wed, Feb 17, 2010 at 3:39 PM, David Mintz <da...@davidmintz.org> wrote:

> I have a class that extends Zend_Form_Subform. In init() I do this:
>
>         $phone = new Zend_Form_Element_Text(
>             array('name' => 'office_phone','id'
> =>'person_office_phone','label' => 'Office phone',
>             'belongsTo' => 'person' ,'class' => 'telephone'
>             )
>         );
>         $phone->addValidator('StringLength',true,array('min'=>10,'max'=>10,
>             'messages' =>     array(
>                  Zend_Validate_StringLength::TOO_SHORT => $m = "phone
> number must be 10 digits",
>                 Zend_Validate_StringLength::TOO_LONG => $m
>         )));
>         $phone->addFilter(new Zend_Filter_Digits());
>         $this->addElement($phone);
>
> I have a Zend_Form subclass that contains two subforms, the above being one
> of them.
>
> In this case I am trying to strip non-digits form a 10-digit phone number.
> When I POST the form with
> "212 805-0362" in this field, validation is failing.
>
> Crude but effective, I put echo statements in Zend_Filter_Digits
> constructor and filter() method, and determined that the Zend_Filter_Digits
> instance is created, but the filter() method is never executed.
>
> Pray tell, what I am doing wrong? Or have I discovered a bug?
>
> This is ZF 1.10.0. Any guidance is deeply appreciated.
>
>
> --
> Support real health care reform:
> http://phimg.org/
>
> --
> David Mintz
> http://davidmintz.org/
>
>
>


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/

Reply via email to