Force a field to lower case
Is there a way to force a field to lower case? For example, I have a field called seo_page_name. (Yes, I've had this long before permalink plug-in existed.) Sometimes users are not as diligent about making sure they use lower case in these fields. I would like to force the field to lower case. I know I can restrict them to using lower case letters, numbers and a dash only, but I would like to take whatever they type into this field and force it to lower case. Is that possible?
Gary, I have this in my snippets library that might be what you're looking for:
<?php echo strtolower($listingsRecord['property_type:label']) ?>
I believe they want this to happen in the CMS as the info is being entered, or after its saved.
Correct (want this to happen in CMS). There's another option I could do. You see, I use this as a permalink.
Deborah - thank you for your response, but that's too late in the process.
What I want to ensure is that http://www.somesite.com/some-page-name will be found in the database. If the SEO page name (or permalink) is Some-Page-Name, it will not be found. I need to ensure it will be. Maybe there's another way around it when I read from the database, such as doing a case insensitive search for the value.
The other concern that I have is that each page MUST have a unique value and I'm afraid that Some-Page-Name and some-page-name are not identical and will not trigger the "unique" flag. If I convert the value to lowercase BEFORE this unique comparison is done, they will be the same.
I was looking around the site to see if there was some documentation on writing add-ons. I could use this approach if nothing else, but I don't know all the hook names for addAction.
I may just go this route if I can figure out how/where to use it. Does anyone know if there are docs on creation of add-ons?
Thanks in advance.
Hi - we have about 150-200 sites right now using CMSB, so I would like to put my add-on in place as we have a reason to touch a site. The permalink add-on is rather costly for doing almost the exact same thing I already do. I just never thought about the case issue before yesterday when a customer couldn't get their links to work correctly...then we figured out why.
I opted to buy the permalink add-on - hopefully that will make life a bit easier - I like the history capability in it - something I have not done. That's worth the cost of it right there.
I'll see how this goes for me.
Good luck. It took me a few sites to get the hang of it, but I really love it now.
What's the exact issue you are trying to solve? CMS Builders built-in unique field checks are case insensitive. And if you have some custom MySQL code you can convert to lowercase with the MySQL LOWER() function.
Hi- to reply to your exact question, I am trying to solve the fact that I use the field seo_page_name to create my navigation scheme in the menus. If I have a MixedCaseValue, my link becomes //www.sitename.com/MixedCaseValue - I want //www.sitename.com/mixedcasevalue instead, so I thought it would be easiest to convert MixedCaseValue to mixedcasevalue when they first enter it, but not force the field to accept only lowercase letters (and numbers and dashes) because it can become frustrating to to users to have to change the value on their own, so I thought I would convert it when they save the record.
I purchased the permalinks add-on, but, as you know, I use CMSB in a much different manner than the out-of-the-box methodology. I will probably have to create my own add-on, but the $150 I spent to buy permalinks will be money well spent to give me a starting point.
I think I know where I can do the strtolower call, or a MySql LOWER call with my current seo_page_name field that it will still work OK without having to do a lot of other stuff. However, I love the history of the permalinks add-on and will add that to mine as soon as I get a chance.
The history will solve the problem of permalinks that are embedded in the content portion of the different pages if/when the permalink changes. The LOWER and strtolower will solve a few other issues and all should be well.
Thank you for replying.