views:

67

answers:

1

Hi All

I've been scouring the net and i have found nothing!

I am using symfonys form framework to build a simple 'Create' form. Validation is fine. However i'd like to pre-filter my submitted values, so adding ucfirst, strtoupper, and the like.

I'm not sure if im missing something crucial here, but the way i see it is the only way to do this would be to create my own custom validators and utilizing the doClean method, which seems daft since i'd have hundreds of validators for each php function!

Hope you guys can help, i've been crawling through source code, api's, numerous books and blogs and i haven't found a thing :( Either it's impossible, or it's really easy, i hope its the latter!

+1  A: 

I apologize for possibly not answering the question, but can you clarify why the values need to be changed prior to binding and validating? This seems like something that could be done as part of sfFormDoctrine::processValues or in the sfFormDoctrine::updateXXXXColumn callbacks. If you're using Propel, there should be similar methods.

jeremy
Thanks for the reply jeremy. It's okay now i think i have got it, i'm going to post an answer to my question later on, but essentially its what you've described. All i did was in my form class that extended doctrines model form class, the method bind(), that way it was performed before validation occurred :) Alternatively though as you rightly said, you can use updateXXXColumn for individual columns
Rob
While you can override bind, values should be updated after binding rather than before unless there is a good reason to do otherwise.
jeremy
well in kohana you set pre filters on form data, i frequently used it to apply things like trim() and ucfirst(), or strtoupper() on all or some fields. As in some cases i want to pre-format data before validating it.
Rob