ZF2 - Form - Apply filters before validation

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

ZF2 - Form - Apply filters before validation

Griesi
Hi all,

 

I am having a form with a input filter attached. The input filter has
filters and validators. So far as I can see, validation does not take
filters into account. Filters are only applied if $form->getData() is
called. Is it possible to apply filters before validation. For example I
have a string filter. This filter fixes common input errors (e.g. replaces
komma with a semicolon). Therefore I want to have the filter applied before
validation is done. The only way to achieve that is to either get and
execute the input filter  before isValid() is called separately or to
set/get and reset the data on the form element. Is there a easier way to do
this?

 

Best Regards

Christian

 

Reply | Threaded
Open this post in threaded view
|

Re: ZF2 - Form - Apply filters before validation

Griesi
I just found out that I am wrong. Filters are in general applied before validation. Except with the FileInput Filter. This filter is only applied if §form->getData() is called. Is this a bug or an intended behaviour? Wouldn´t it make sense to at least apply the filter automatically if the form isValid?
Reply | Threaded
Open this post in threaded view
|

Re: ZF2 - Form - Apply filters before validation

weierophinney
Administrator
On Thu, Apr 11, 2013 at 12:32 PM, Griesi <[hidden email]> wrote:
> I just found out that I am wrong. Filters are in general applied before
> validation. Except with the FileInput Filter. This filter is only applied if
> §form->getData() is called. Is this a bug or an intended behaviour? Wouldn´t
> it make sense to at least apply the filter automatically if the form
> isValid?

Intended behavior. The reason is that we need to make sure that the
$_FILES entry is valid before we do anything irrevocable, such as
moving the file into a storage directory, renaming it, etc. As such,
file filters need to be invoked after validation.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: ZF2 - Form - Apply filters before validation

Griesi

OK. But wouldn't it make sense hat the filter is automatically applied if the form has been validated as a whole? Currently you need to call get data. If you do not need to call getData because the form does not have  any other input fields than file and you already provide the target file name for the filter it is a hard to track why the filter does not work

Am 15.04.2013 15:22 schrieb "weierophinney [via Zend Framework Community]" <[hidden email]>:
On Thu, Apr 11, 2013 at 12:32 PM, Griesi <[hidden email]> wrote:
> I just found out that I am wrong. Filters are in general applied before
> validation. Except with the FileInput Filter. This filter is only applied if
> §form->getData() is called. Is this a bug or an intended behaviour? Wouldn´t
> it make sense to at least apply the filter automatically if the form
> isValid?

Intended behavior. The reason is that we need to make sure that the
$_FILES entry is valid before we do anything irrevocable, such as
moving the file into a storage directory, renaming it, etc. As such,
file filters need to be invoked after validation.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]





If you reply to this email, your message will be added to the discussion below:
http://zend-framework-community.634137.n4.nabble.com/ZF2-Form-Apply-filters-before-validation-tp4659701p4659719.html
To unsubscribe from ZF2 - Form - Apply filters before validation, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: ZF2 - Form - Apply filters before validation

weierophinney
Administrator
On Mon, Apr 15, 2013 at 8:44 AM, Griesi <[hidden email]> wrote:
> OK. But wouldn't it make sense hat the filter is automatically applied if
> the form has been validated as a whole? Currently you need to call get
> data. If you do not need to call getData because the form does not have
> any other input fields than file and you already provide the target file
> name for the filter it is a hard to track why the filter does not work

The workflow for forms is:

- setData()
- isValid()
- getData() (or, if using object binding, just access the object you bound)
- OR getMessages() (if the form was invalid)

That's the workflow.

File uploads are odd because they have side effects. I think it's
better to have an explicit point at which the side effects occur, and
doing it as part of getData(), when the values are mapped, makes the
most sense.

> Am 15.04.2013 15:22 schrieb "weierophinney [via Zend Framework Community]" <
> [hidden email]>:
>
>> On Thu, Apr 11, 2013 at 12:32 PM, Griesi <[hidden email]<http://user/SendEmail.jtp?type=node&node=4659719&i=0>>
>> wrote:
>> > I just found out that I am wrong. Filters are in general applied before
>> > validation. Except with the FileInput Filter. This filter is only
>> applied if
>> > §form->getData() is called. Is this a bug or an intended behaviour?
>> Wouldn´t
>> > it make sense to at least apply the filter automatically if the form
>> > isValid?
>>
>> Intended behavior. The reason is that we need to make sure that the
>> $_FILES entry is valid before we do anything irrevocable, such as
>> moving the file into a storage directory, renaming it, etc. As such,
>> file filters need to be invoked after validation.
>>
>> --
>> Matthew Weier O'Phinney
>> Project Lead            | [hidden email]<http://user/SendEmail.jtp?type=node&node=4659719&i=1>
>> Zend Framework          | http://framework.zend.com/
>> PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
>>
>> --
>> List: [hidden email]<http://user/SendEmail.jtp?type=node&node=4659719&i=2>
>> Info: http://framework.zend.com/archives
>> Unsubscribe: [hidden email]<http://user/SendEmail.jtp?type=node&node=4659719&i=3>
>>
>>
>>
>>
>> ------------------------------
>>  If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://zend-framework-community.634137.n4.nabble.com/ZF2-Form-Apply-filters-before-validation-tp4659701p4659719.html
>>  To unsubscribe from ZF2 - Form - Apply filters before validation, click
>> here<
>> .
>> NAML<
http://zend-framework-community.634137.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>
>
>
>
> --
> View this message in context: http://zend-framework-community.634137.n4.nabble.com/ZF2-Form-Apply-filters-before-validation-tp4659701p4659721.html
> Sent from the Zend Framework mailing list archive at Nabble.com.



--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: ZF2 - Form - Apply filters before validation

londonladiesinred
This post has NOT been accepted by the mailing list yet.
thank you for this post ,very usefull