Is there any way to validate attributes?

Permalink
I'm wondering what the best way is to validate attributes? Seems like this is a pretty major thing that is lacking from concrete 5. Perhaps there should be a validate function in the attribute controller that is called whenever a the form is saved? How would you do this? I want to work on a custom 'location' attribute that would validate that you had a lattitude and longitude entered, I'm just not sure exactly how to do this.

hereNT
 
aghouseh replied on at Permalink Reply
aghouseh
You can check out jshannon's lerteco advanced text attribute (http://www.concrete5.org/marketplace/addons/lerteco-advanced-text-attribute/). His attrib allows for a custom regex to validate any sort of text input against. If you want more specific functionality, I would just create your own attrib type. They are actually quite simple to create. Just drop by IRC if you go that route and run into any problems.
hereNT replied on at Permalink Reply
hereNT
I saw that he had created it but I'm asking more if there should be a built in system for validating them. His uses javascript in the view to do the validation, I'd rather have it in PHP on the controller if possible. I've made my own attribute types before.
aghouseh replied on at Permalink Reply
aghouseh
That's actually what motivated him to create it. We were discussing how such a system should be built-in to C5, but there was no such beast. 24hours later or thereabouts and he had it done. I agree wholeheartedly that it should be in the core, but I'm not sure of the official stance on it.
andrew replied on at Permalink Reply
andrew
You can define validateForm() in you attribute and then use it to validate whether the attribute is being submitted properly. It's pretty binary – either it returns true if it's valid or false if it's not, but we use this in the ecommerce add-on and the address attribute type.

It's not hooked to in the core interface yet – meaning it doesn't run automatically in page attributes view, file attributes view, etc... but you can use it in your own custom views.