2009年2月24日星期二

Re: [fw-mvc] Zend Forms and Filters

Allright...

I noticed the $form->getValues(), but placed it before the $form->isValid().
Didn't work there, but after isValid seems to be working fine!

Thanks


PHPScriptor wrote:
>
> Hey,
>
> I've a little question how I could deal with Forms and Filters.
>
> Lets say, I put a filter on an element that will change my input value.
> Only, I find it always strange that, from the moment I do getPost I get
> the unfiltered values.
>
> What I do know, after the getPost I do:
> $formData['day'] = Zend_Filter_MyFilter::filter($formData['day']);
>
> In my opinion, I have to do 2 times the filter just to get the correct
> value. In this example I only have to do it once, but what if I have 7
> Filters in a form, it becomes a lot of work and code.
> Isn't there a way to set the filter on the formelements, en get the
> filtered values in the controller?
>
> // form
> $formElements[]= self::createElement('text','day')
> ->addValidator('int')
> ->addFilter(new Zend_Filter_MyFilter())
> ->addValidator('Between',false, array(0,24));
>
> // controller
> if ($this->_request->isPost()) {
> $formData = $this->_request->getPost();
> if ($form->isValid($formData)) {
> ... // submit value to db
> }
> }
>


-----
visit my website at http://www.phpscriptor.com/ http://www.phpscriptor.com/
--
View this message in context: http://www.nabble.com/Zend-Forms-and-Filters-tp22179829p22181851.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: