Validation Rules
This is an open discussion with 7 replies, filed under Troubleshooting.
Search
You may be interested in symphony/lib/toolkit/util.validators.php
. Copy one of the existing assignments within $validators and edit it for your own purposes--take heed of course of the warning:
## Be aware that this file may be updated, losing any changes you have made. Always ## make backups. If you would like a rule offically included in a distribution ## of Symphony, please contact the development team (team@symphony21.com)
Thanks for the tip. Works perfect.
Am I right in assuming that the following:
/.(?:doc|pdf|rtf|txt)$/i
Can be expanded to include other document types? such as Excel?
/.(?:doc|pdf|rtf|txt|xls)$/i
Sure, You can simply remove or add extensions in this expression.
Yes indeed. Note that the procedure for adding new validation rules has changed slightly — instructions are inside the util.validators.php
file referenced above. In short, create a file of the same name and put it inside your /manifest
directory, and you can define your own validation regular expressions that won’t be overwritten when you upgrade your Symphony core.
@Nick: That’s cool, I did not know that.
(Note: The file in your manifest
directory must not have the same name, but be called validators.php
)
Still if you need a rule just once, you may simply edit the validation string for your field manually.
I have an audio/video encoding extension we use internally (it won’t be released any time soon as it doesn’t work out of the box and requires many server components to be installed), but I always have to add a validators.php
file:
// Media Encoder $upload['video'] = '/.(?:aiff|3gp|avi|mp4|mpeg4|mpeg|mov|m4v|flv)$/i'; $upload['audio'] = '/.(?:wav|mp3|mp4|aif|aiff|ogg|flac|aac|m4a)$/i';
It would be nice if Extensions could also provide these regular expressions themselves.
Create an account or sign in to comment.
I really appreciate the built-in validation rules for text inputs. There are several other validation rules that I would like to use repetitively, but am inexperienced in php. What is the process for adding more rules? The attached screenshot shows what I am referring to, as well as an example of a rule I would like to reuse often. Thanks in advance for any help.
Attachments