Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Validate custom field names
Sometimes bread needs butter:
- Preferences panel throws out an error/notice/warning if customfield’s name doesn’t follow the valid scheme.
- Or core auto-corrects the name (trim spaces, [a-z-0-9] etc).
Many ppl do seem to use invalid chars in their tasty little fields, and when used, well the SQL ain’t going to work.
Last edited by Gocom (2009-09-12 05:54:17)
Offline
Re: Validate custom field names
Custom field labels are never used in SQL queries anyway. When building the SQL query, the label is translated to the corresponding table column name.
The only problem is that when parsing tags, the attribute names have to be valid and that conflicts with a free format label.
A different approach would be to simply not use the custom field labels as attribute names, but instead switch to using the actual custom field table column names (you have to do that anyway if you want to use them in the ‘sort’ attribute). That also solves problems with labels that conflict with other internal variables.
One could argue that working with fields like custom_1 is less user friendly than working with “my pretty label”, but you’d really be using the column names only in the templates which are usually created by a user who should have a fair bit of technical clue anyway. The labels would still show on the write tab where the less technical user needs them.
Offline
#3 2009-09-12 11:56:08
- redbot
- Plugin Author
- Registered: 2006-02-14
- Posts: 1,410
Re: Validate custom field names
ruud wrote:
A different approach would be to simply not use the custom field labels as attribute names, but instead switch to using the actual custom field table column names…
Totally agree. Another annoying consequence of the current mechanism is that you can’t use spaces in the cf name.
Well… actually you can but if you do you won’t be able to use the field as an attribute for article _custom tag.
In other words if my cf name is “a name” I can’t write this:
<txp:article_custom a name="john" />
Offline
Re: Validate custom field names
ruud wrote:
Custom field labels are never used in SQL queries anyway. When building the SQL query, the label is translated to the corresponding table column name.
The only problem is that when parsing tags, the attribute names have to be valid and that conflicts with a free format label.
Yeah, I know. I just used word SQL, but that is the ending result ;)
Well, one way ofcourse is that the parser could include the spaces etc. in the att parsing, but then there ‘might’ rise performance issues etc.
ruud wrote:
A different approach would be to simply not use the custom field labels as attribute names, but instead switch to using the actual custom field table column names (you have to do that anyway if you want to use them in the ‘sort’ attribute). That also solves problems with labels that conflict with other internal variables.
That’s good way too. Only thing is the backwards thingy. Tho, the parser could also allow the usage of labels. Then we could argue how nasty it looks to keep the extra code in there.
Last edited by Gocom (2009-09-12 12:11:01)
Offline