Filtering input and similar
Posted: Tue Apr 15, 2008 8:33 pm
Personally, I am tired of validating forms and manipulating the data so that it's ready to be inserted into a database or whatever. In addition, I was finding that I had to cast POST data into ints to use with Creole, which was just one more annoying little thing. Finally, I found it really annoying to communicate errors to the user because my error discovery and error messages were in different files.
So, I wrote an example XML file describing what I wanted. I've copied it below:
Any comments on the XML are appreciated. A nice observation is that you could use this same XML to describe how to manipulate data on its way out of the application. For instance, to transform timestamps to strings before passing the data to some template.
I'd love some advice with the code I've written to turn this XML file into something that does work. It's all rough (and poorly named) but I think it's worth looking at. What's most important in my mind is that it be easy for myself or others to write new filters/transforms in the future.
I'd also love some suggestions on how to modify the current code to allow for aggregate operations. For instance, checking that two fields in the collection matched (say password and confirmed password).
The code is attached. Thanks!
So, I wrote an example XML file describing what I wanted. I've copied it below:
Code: Select all
<sample>
<field name="title">
<filter type="String" emsg="Must specify a title." />
<filter type="Callback" emsg="Title must be unique.">
<arg name="callback" value="Movie::isUnique" />
</filter>
</field>
<field name="rating">
<filter type="Int" emsg="Must specify a rating between 1 and 5.">
<arg name="min" value="1" />
<arg name="max" value="5" />
</filter>
<transform type="Int" />
</field>
</sample>
I'd love some advice with the code I've written to turn this XML file into something that does work. It's all rough (and poorly named) but I think it's worth looking at. What's most important in my mind is that it be easy for myself or others to write new filters/transforms in the future.
I'd also love some suggestions on how to modify the current code to allow for aggregate operations. For instance, checking that two fields in the collection matched (say password and confirmed password).
The code is attached. Thanks!